From 0903416a020ef8fe5ada9799a2c532433df3b520 Mon Sep 17 00:00:00 2001
From: khonkhortisan khonkhorti...@gmail.com
Date: Sun, 30 Nov 2014 20:57:47 -0800
Subject: [PATCH xkill] Use secondary mouse pointers
---
configure.ac | 2 +-
man/xkill.man | 8 +++-
xkill.c | 130 +-
3 files changed, 110 insertions(+), 30 deletions(-)
diff --git a/configure.ac b/configure.ac
index 6af4b04..32b68c0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,7 +38,7 @@ XORG_MACROS_VERSION(1.8)
XORG_DEFAULT_OPTIONS
# Checks for pkg-config packages
-PKG_CHECK_MODULES(XKILL, [x11 xmuu xproto = 7.0.22])
+PKG_CHECK_MODULES(XKILL, [xi x11 xmuu xproto = 7.0.22])
AC_CONFIG_FILES([
Makefile
diff --git a/man/xkill.man b/man/xkill.man
index 6cddc0a..23a2c4c 100644
--- a/man/xkill.man
+++ b/man/xkill.man
@@ -27,7 +27,7 @@
xkill - kill a client by its X resource
.SH SYNOPSIS
.B xkill
-[\-display \fIdisplayname\fP] [\-id \fIresource\fP] [\-button number] [\-frame] [\-all] [\-version]
+[\-display \fIdisplayname\fP] [\-id \fIresource\fP] [\-pointer id] [\-button number] [\-frame] [\-all] [\-version]
.SH DESCRIPTION
.PP
.I Xkill
@@ -48,6 +48,12 @@ This option specifies the X identifier for the resource whose creator is
to be aborted. If no resource is specified, \fIxkill\fP will display a
special cursor with which you should select a window to be kill.
.TP 8
+.B \-pointer \fIid\fP
+This option specifies the id of a mouse pointer that may be used in
+selecting a window to kill. This id must match the number given by xinput(1).
+If the pointer is specified, any other pointers are ignored.
+By default, every pointer is used.
+.TP 8
.B \-button \fInumber\fP
This option specifies the number of pointer button
that should be used in selecting a window to kill.
diff --git a/xkill.c b/xkill.c
index 32cb0cc..1e6a26c 100644
--- a/xkill.c
+++ b/xkill.c
@@ -45,6 +45,7 @@ from The Open Group.
#include X11/Xos.h
#include X11/Xlib.h
+#include X11/extensions/XInput2.h
#include X11/cursorfont.h
#include X11/Xproto.h
@@ -52,11 +53,12 @@ from The Open Group.
static char *ProgramName;
+#define SelectPointerAny (-1)
#define SelectButtonAny (-1)
#define SelectButtonFirst (-2)
static int parse_button ( char *s, int *buttonp );
-static XID get_window_id ( Display *dpy, int screen, int button, const char *msg );
+static XID get_window_id ( Display *dpy, int screen, int pointer_id, int button, const char *msg );
static int catch_window_errors ( Display *dpy, XErrorEvent *ev );
static int kill_all_windows ( Display *dpy, int screenno, Bool top );
static int verify_okay_to_kill ( Display *dpy, int screenno );
@@ -80,6 +82,7 @@ usage(const char *errmsg)
-display displaynameX server to contact\n
-id resourceresource whose client is to be killed\n
-frame don't ignore window manager frames\n
+-pointer id specific mouse pointer to use for killing a window\n
-button number specific button to be pressed to select window\n
-allkill all clients with top level windows\n
-versionprint version and exit\n
@@ -101,12 +104,14 @@ main(int argc, char *argv[])
char *displayname = NULL; /* name of server to contact */
int screenno; /* screen number of dpy */
XID id = None; /* resource to kill */
+int pointer_id; /* number of mouse pointer to grab */
char *button_name = NULL; /* name of button for window select */
int button;/* button number or negative for all */
Bool kill_all = False;
Bool top = False;
ProgramName = argv[0];
+pointer_id = SelectPointerAny;
button = SelectButtonFirst;
for (i = 1; i argc; i++) {
@@ -127,6 +132,10 @@ main(int argc, char *argv[])
Exit (1, dpy);
}
continue;
+ case 'p':
+ if (++i = argc) usage (-pointer requires an argument);
+ pointer_id = strtoul (argv[i], NULL, 0);
+ continue;
case 'b': /* -button number */
if (++i = argc) usage (-button requires an argument);
button_name = argv[i];
@@ -208,7 +217,7 @@ main(int argc, char *argv[])
button = (int) ((unsigned int) pointer_map[0]);
}
}
- if ((id = get_window_id (dpy, screenno, button,
+ if ((id = get_window_id (dpy, screenno, pointer_id, button,
the window whose client you wish to kill))) {
if (id == RootWindow(dpy,screenno)) id = None;
else if (!top) {
@@ -270,15 +279,18 @@ parse_button(char *s, int *buttonp)
}
static XID
-get_window_id(Display *dpy, int screen, int button, const char *msg)
+get_window_id(Display *dpy, int screen, int pointer_id, int button, const char *msg)
{
Cursor cursor; /* cursor to use when selecting */
Window root; /* the current root */
Window retwin = None; /* the window that got selected */
int retbutton = -1; /* button used to select window */
int pressed = 0; /* count of number