xr

simple and small util to control Xorg server remotely.
git clone git://git.kocotian.pl/xr.git
Log | Files | Refs | README | LICENSE

commit f7bed9bb4c963a7daa985cb02f0f3e2a1c214d2a
parent 4f5981da80928e950f6eb3fe5a4a8dc5c52661fc
Author: kocotian <kocotian@kocotian.pl>
Date:   Fri, 12 Mar 2021 09:52:37 +0100

fixes, mods, typing

Diffstat:
Mxr.c | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 65 insertions(+), 10 deletions(-)

diff --git a/xr.c b/xr.c @@ -5,7 +5,10 @@ static void xclick(char *b); static void xkey(char *k); +static void xkeydown(char *k); +static void xkeyup(char *k); static void xmousemove(char *x, char *y); +static void xtype(char *k); static void xdotool(char *argv[]); static void @@ -29,6 +32,26 @@ xkey(char *k) } static void +xkeydown(char *k) +{ + char *argv[] = { + "xdotool", "keydown", "--", + k, NULL + }; + xdotool(argv); +} + +static void +xkeyup(char *k) +{ + char *argv[] = { + "xdotool", "keyup", "--", + k, NULL + }; + xdotool(argv); +} + +static void xmousemove(char *x, char *y) { char *argv[] = { @@ -39,6 +62,16 @@ xmousemove(char *x, char *y) } static void +xtype(char *k) +{ + char *argv[] = { + "xdotool", "type", "--", + k, NULL + }; + xdotool(argv); +} + +static void xdotool(char *argv[]) { if (fork() == 0) @@ -48,8 +81,8 @@ xdotool(char *argv[]) int main(void) { - int key, mode; - mode = 0; + int key, mode, mod; + mode = mod = 0; write(1, "\033[2J\033[H", 7); while ((key = getch(0))) { write(1, "\033[2J\033[H", 7); @@ -78,6 +111,11 @@ main(void) case ' ': xclick("1"); break; + case 'q': mod ^= 1 << 0; break; + case 'w': mod ^= 1 << 1; break; + case 'e': mod ^= 1 << 2; break; + case 'r': mod ^= 1 << 3; break; + break; } break; } @@ -85,13 +123,7 @@ main(void) if (key == 033) { mode = 0; } else { - if ((key >= 'a' && key <= 'z') - || (key >= 'A' && key <= 'Z') - || (key >= '0' && key <= '9')) { - char k[2]; - snprintf(k, 2, "%c", key); - xkey(k); - } else switch (key) { + switch (key) { case ' ': puts("*space*"); xkey("space"); @@ -108,12 +140,35 @@ main(void) puts("*escape*"); xkey("Escape"); break; + default: { + char k[2]; + snprintf(k, 2, "%c", + key); + xtype(k); + break; + } } } break; } } + if (mod & 1 << 0) { + write(1, "[Control Mask]\n", 15); + xkeydown("Control"); + } else xkeyup("Control"); + if (mod & 1 << 1) { + write(1, "[Alt Mask]\n", 11); + xkeydown("Alt"); + } else xkeyup("Alt"); + if (mod & 1 << 2) { + write(1, "[Shift Mask]\n", 13); + xkeydown("Shift"); + } else xkeyup("Shift"); + if (mod & 1 << 3) { + write(1, "[Super Mask]\n", 13); + xkeydown("Super"); + } else xkeyup("Super"); if (mode == 1) - write(1, "-- INSERT MODE --\r", 18); + write(1, "-- INSERT MODE --", 18); } }