Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -109,6 +111,10 @@ main(int argc, char *argv[])
ignored |= mods[i].mask;

break;
case 'k':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation seems messed up, ensure you're using TABs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fixed. I forgot to change my editor config. I added an .editorconfig file just for me 😄

// choose which keyboard device to listen only (in case of xremap or Kmonad being used)
master_keyboard_device = strdup(optarg);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strdup can fail since it allocates memory and so the return value needs to be checked.

But in this case, there should be zero reason to duplicate the string to begin with.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, should be fixed

break;
case 'm':
if (strcmp(optarg, "nw") == 0)
move = MOVE_NW;
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