aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2020-10-04 15:31:39 +0200
committerOmar Polo <op@omarpolo.com>2020-10-04 15:31:39 +0200
commit2eb11d8ec14963a978a1811f5d0beca158d64f50 (patch)
treec5847b65b3f00539c32849e74dd7d7fa5e7f28f1
parent7c6a610b98e344ef485f60862db46ec271a50c5a (diff)
downloadstar-platinum-2eb11d8ec14963a978a1811f5d0beca158d64f50.tar.gz
star-platinum-2eb11d8ec14963a978a1811f5d0beca158d64f50.tar.bz2
rework send_fake: copy as much as possible from the original event
send_fake now copies almost all field from the original event, except for the the window, keycode and state field. When we grab a key we grab it onto the root window, so every event we receive has a field window that is equal to the root. (this will change in the future), so we need to change that. The keycode and state obviously need to be changed, it's the whole point of the function. It doesn't seem to fix the known bug that occur in dino thought.
-rw-r--r--star-platinum.c41
-rw-r--r--star-platinum.h4
2 files changed, 25 insertions, 20 deletions
diff --git a/star-platinum.c b/star-platinum.c
index ebe717c..3db2088 100644
--- a/star-platinum.c
+++ b/star-platinum.c
@@ -271,28 +271,33 @@ focused_window()
}
void
-send_fake(Window w, struct key k, int pressed)
+send_fake(Window w, struct key k, XKeyEvent *original)
{
XKeyEvent e;
- e.type = pressed ? KeyPress : KeyRelease;
-
- e.display = d;
+ /*
+ * this needs to be hijacked. original->window is the root
+ * window (since we grabbed the key there) and we want to
+ * deliver the key to another window.
+ */
e.window = w;
- e.root = DefaultRootWindow(d);
- e.subwindow = None;
- e.time = CurrentTime;
- /* TODO: fix these */
- e.x = 1;
- e.y = 1;
- e.x_root = 1;
- e.y_root = 1;
-
- e.same_screen = True;
+ /* this is the fake key */
e.keycode = XKeysymToKeycode(d, k.key);
e.state = k.modifier;
+ /* the rest is just copying fields from the original event */
+ e.type = original->type;
+ e.display = original->display;
+ e.root = original->root;
+ e.subwindow = original->subwindow;
+ e.time = original->time;
+ e.same_screen = original->same_screen;
+ e.x = original->x;
+ e.y = original->y;
+ e.x_root = original->x_root;
+ e.y_root = original->y_root;
+
XSendEvent(d, w, True, KeyPressMask, (XEvent*)&e);
XFlush(d);
}
@@ -320,11 +325,11 @@ window_match_class(Window w, const char *class)
/* action */
void
-do_action(struct action a, Window focused, int pressed)
+do_action(struct action a, Window focused, XKeyEvent *original)
{
switch (a.type) {
case AFAKE:
- send_fake(focused, a.send_key, pressed);
+ send_fake(focused, a.send_key, original);
break;
case ASPECIAL:
@@ -510,13 +515,13 @@ process_event(struct group *g, XKeyEvent *e)
for (r = g->rules; r != NULL; r = r->next) {
if (rule_matched(r, pressed)) {
- do_action(r->action, focused, e->type == KeyPress);
+ do_action(r->action, focused, e);
return;
}
}
}
- send_fake(focused, pressed, e->type == KeyPress);
+ send_fake(focused, pressed, e);
}
int
diff --git a/star-platinum.h b/star-platinum.h
index f6a752b..83905bd 100644
--- a/star-platinum.h
+++ b/star-platinum.h
@@ -50,7 +50,7 @@ struct action {
};
};
-void do_action(struct action, Window, int);
+void do_action(struct action, Window, XKeyEvent*);
void free_action(struct action);
struct match {
@@ -93,7 +93,7 @@ int error_handler(Display*, XErrorEvent*);
void grabkey(struct key);
KeySym keycode_to_keysym(unsigned int);
Window focused_window();
-void send_fake(Window, struct key, int);
+void send_fake(Window, struct key, XKeyEvent*);
int window_match_class(Window, const char*);
/* debugging */