Skip to content

Instantly share code, notes, and snippets.

@twaik
twaik / xterm_get_mouse_click_and_chars.c
Last active December 27, 2023 08:53
Getting mouse clicks on xterm.
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
enum {
KEYSTATE_NONE = 1024,
KEYSTATE_ESCAPE,
KEYSTATE_CONTROL,
KEYSTATE_MOUSE_PROPS
@twaik
twaik / updater.c
Last active November 15, 2024 14:41
This programm updates /dev/graphics/fb0 if it doesn't do it automatically
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <time.h>
int main(int argc, char *argv[])
@twaik
twaik / drawing-pixmaps.c
Last active July 13, 2018 14:55
Drawing pixmaps using libX11
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
@twaik
twaik / scanner.c
Created August 5, 2019 08:23
Wayland server protocol c++ scanner
/*
* Copyright © 2008-2011 Kristian Høgsberg
* Copyright © 2011 Intel Corporation
* Copyright © 2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
@twaik
twaik / libinput-superkey-menu.c
Created October 22, 2021 18:16
Restore showing Application Menu with Super key using libinput. Needs a user to be in `input` group. Based on `libinput-debug-events.c` code.
/*
* Copyright © 2014 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
@twaik
twaik / build.gradle
Last active July 4, 2023 17:58
Gradle waylandpp's wayland-scanner++ task
/*
* This code is based on
* https://github.com/NilsBrause/waylandpp/blob/4321ed5c7b4bffa41b8a2a13dc7f3ece1191f4f3/scanner/scanner.cpp
* and should generate code identical to wayland-scanner++
*
* It is created to be used as gradle task in Android Studio builds where we can not use generators
* (crosscompilation does not allow us build code for host).
*/
import org.xml.sax.SAXException
@twaik
twaik / randr_dump.c
Created January 24, 2023 23:03
The tool to dump current displays layout the same way it is done by arandr...
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#define startsWith(a, b) (strstr(a, b) == a)
int main() {
char chunk[512];
@twaik
twaik / randr_add_resolution_range.cpp
Created February 7, 2023 19:58
Some code which should add a few resolutions to xserver using randr extension with xcb.
#include <iostream>
#include <xcb/xcb.h>
#include <xcb/randr.h>
#include <cstring>
class main {
public:
main();
xcb_connection_t* conn{};
@twaik
twaik / xclip.cpp
Created March 8, 2023 01:39
Pretty stupido code printing clipboard contents to stdout. Was written with help of xcb and xclip in xcb.
#include <iostream>
#include <xcb/xcb.h>
#include <xcb/bigreq.h>
#define explicit c_explicit
#include <xcb/xkb.h>
int main() {
xcb_connection_t *c = xcb_connect(":1", nullptr);