Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to specify master keyboard #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions xbanish.1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.Op Fl a
.Op Fl d
.Op Fl i Ar modifier
.Op Fl k Ar keyboard_prefix
.Op Fl m Oo Ar w Oc Ns Ar nw|ne|sw|se|\(+-x\(+-y
.Op Fl t Ar seconds
.Op Fl s
Expand Down Expand Up @@ -49,6 +50,8 @@ Modifiers are:
.Ic mod5
(ISO Level 3 Shift), and
.Ic all
.It Fl k Ar keyboard_prefix
When used, will only attach to the keyboards device that match the start of the argument. Useful when running kmonad or xremap.
.It Fl m Oo Ar w Oc Ns Ar nw|ne|sw|se|\(+-x\(+-y
When hiding the mouse cursor, move it to this corner of the screen
or current window, then move it back when showing the cursor.
Expand Down
14 changes: 12 additions & 2 deletions xbanish.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ static unsigned char ignored;
static XSyncCounter idler_counter = 0;
static XSyncAlarm idle_alarm = None;

static char *master_keyboard_device;

static int debug = 0;
#define DPRINTF(x) { if (debug) { printf x; } };

Expand Down Expand Up @@ -94,7 +96,7 @@ main(int argc, char *argv[])
{"all", -1},
};

while ((ch = getopt(argc, argv, "adi:m:t:s")) != -1)
while ((ch = getopt(argc, argv, "adi:k:m:t:s")) != -1)
switch (ch) {
case 'a':
always_hide = 1;
Expand All @@ -108,6 +110,10 @@ main(int argc, char *argv[])
if (strcasecmp(optarg, mods[i].name) == 0)
ignored |= mods[i].mask;

break;
case 'k':
// choose which keyboard device to listen only (in case of xremap or Kmonad being used)
master_keyboard_device = optarg;
break;
case 'm':
if (strcmp(optarg, "nw") == 0)
Expand Down Expand Up @@ -463,6 +469,10 @@ snoop_xinput(Window win)
ici++, j++) {
switch (ici->input_class) {
case KeyClass:
if (master_keyboard_device &&
strncmp(master_keyboard_device, devinfo[i].name, strlen(master_keyboard_device)) != 0)
continue;

DPRINTF(("attaching to keyboard device %s "
"(use %d)\n", devinfo[i].name,
devinfo[i].use));
Expand Down Expand Up @@ -587,7 +597,7 @@ set_alarm(XSyncAlarm *alarm, XSyncTestType test)
void
usage(char *progname)
{
fprintf(stderr, "usage: %s [-a] [-d] [-i mod] [-m [w]nw|ne|sw|se|+/-xy] "
fprintf(stderr, "usage: %s [-a] [-d] [-i mod] [-k master_keyboard] [-m [w]nw|ne|sw|se|+/-xy] "
"[-t seconds] [-s]\n", progname);
exit(1);
}
Expand Down