#define YESNO(x) ((x) ? "yes" : "no")
#define SWM_FOCUS_DEFAULT (0)
-#define SWM_FOCUS_SYNERGY (1)
-#define SWM_FOCUS_FOLLOW (2)
+#define SWM_FOCUS_FOLLOW (1)
+#define SWM_FOCUS_MANUAL (2)
#define SWM_CONF_DEFAULT (0)
#define SWM_CONF_KEYMAPPING (1)
void configurerequest(xcb_configure_request_event_t *);
void constrain_window(struct ws_win *, struct swm_region *, int);
void destroynotify(xcb_destroy_notify_event_t *);
-void do_sync(void);
void enternotify(xcb_enter_notify_event_t *);
void event_drain(uint8_t);
void event_error(xcb_generic_error_t *);
struct ws_win *find_window(xcb_window_t);
int floating_toggle_win(struct ws_win *);
void focus(struct swm_region *, union arg *);
+void focus_flush(void);
struct ws_win *focus_magic(struct ws_win *);
+void focus_win(struct ws_win *);
#ifdef SWM_DEBUG
void focusin(xcb_focus_in_event_t *);
#endif
xcb_screen_t *get_screen(int);
char *get_win_name(xcb_window_t);
uint32_t getstate(xcb_window_t);
-void grabbuttons(struct ws_win *, int);
+void grabbuttons(struct ws_win *);
void keypress(xcb_key_press_event_t *);
#ifdef SWM_DEBUG
void leavenotify(xcb_leave_notify_event_t *);
}
void
-do_sync(void)
+focus_flush(void)
{
- xcb_get_input_focus_cookie_t c;
- xcb_get_input_focus_reply_t *r;
-
- /* mimic XSync() */
- c = xcb_get_input_focus(conn);
- xcb_flush(conn);
- r = xcb_get_input_focus_reply(conn, c, NULL);
- if (r)
- free(r);
+ if (focus_mode == SWM_FOCUS_DEFAULT)
+ event_drain(XCB_ENTER_NOTIFY);
+ else
+ xcb_flush(conn);
}
void
/* must be after stack */
bar_update();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
void
win->ws->focus_prev = NULL;
}
- grabbuttons(win, 0);
xcb_change_window_attributes(conn, win->id, XCB_CW_BORDER_PIXEL,
&win->ws->r->s->c[SWM_S_COLOR_UNFOCUS].pixel);
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win->s->root,
cur_focus = r->focus;
free(r);
}
- if ((cfw = find_window(cur_focus)) != NULL)
+
+ cfw = find_window(cur_focus);
+
+ if (cfw == win) {
+ if (win->ws->focus == win) {
+ DNPRINTF(SWM_D_FOCUS, "focus_win: already focused; "
+ "skipping.\n");
+ return;
+ } else {
+ DNPRINTF(SWM_D_FOCUS, "focus_win: already has input "
+ "focus.\n");
+ }
+ } else
unfocus_win(cfw);
win->ws->focus = win;
if (win->java == 0)
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT,
win->id, XCB_CURRENT_TIME);
- grabbuttons(win, 1);
xcb_change_window_attributes(conn, win->id,
XCB_CW_BORDER_PIXEL,
&win->ws->r->s->c[SWM_S_COLOR_FOCUS].pixel);
TAILQ_FOREACH(win, &old_ws->winlist, entry)
unmap_window(win);
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
DNPRINTF(SWM_D_WS, "switchws: done\n");
}
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
void
a.id = SWM_ARG_ID_FOCUSCUR;
focus(r, &a);
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
void
stack();
bar_update();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
void
if (r->ws->always_raise == 0)
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
void
a.id = SWM_ARG_ID_FOCUSCUR;
focus(r, &a);
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
char *
focus(win->ws->r, &a);
}
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
void
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
switch (args->id) {
case SWM_ARG_ID_WIDTHSHRINK:
/* not free, don't sync more than 120 times / second */
if ((mne->time - timestamp) > (1000 / 120) ) {
timestamp = mne->time;
- do_sync();
update_window(win);
+ xcb_flush(conn);
}
break;
default:
free(evt);
}
if (timestamp) {
- do_sync();
update_window(win);
+ xcb_flush(conn);
}
store_float_geom(win,r);
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
move_step = 0;
switch (args->id) {
/* not free, don't sync more than 120 times / second */
if ((mne->time - timestamp) > (1000 / 120) ) {
timestamp = mne->time;
- do_sync();
update_window(win);
+ xcb_flush(conn);
}
break;
default:
free(evt);
}
if (timestamp) {
- do_sync();
update_window(win);
+ xcb_flush(conn);
}
store_float_geom(win, r);
free(qpr);
}
void
-grabbuttons(struct ws_win *win, int focused)
+grabbuttons(struct ws_win *win)
{
+#if 0
int i;
+#endif
+
+ DNPRINTF(SWM_D_MOUSE, "grabbuttons: win 0x%x\n", win->id);
+#if 0
xcb_ungrab_button(conn, XCB_BUTTON_INDEX_ANY, win->id,
XCB_BUTTON_MASK_ANY);
- if (focused) {
- for (i = 0; i < LENGTH(buttons); i++)
- if (buttons[i].action == client_click)
- xcb_grab_button(conn, 0, win->id,
- BUTTONMASK,
- XCB_GRAB_MODE_ASYNC,
- XCB_GRAB_MODE_SYNC,
- XCB_WINDOW_NONE,
- XCB_CURSOR_NONE,
- buttons[i].button,
- buttons[i].mask);
- } else
- xcb_grab_button(conn, 0, win->id, BUTTONMASK,
- XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_WINDOW_NONE,
- XCB_CURSOR_NONE, XCB_BUTTON_INDEX_ANY, XCB_BUTTON_MASK_ANY);
+
+ for (i = 0; i < LENGTH(buttons); i++)
+ if (buttons[i].action == client_click)
+ xcb_grab_button(conn, 0, win->id, BUTTONMASK,
+ XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
+ XCB_WINDOW_NONE, XCB_CURSOR_NONE,
+ buttons[i].button, buttons[i].mask);
+#endif
+ xcb_grab_button(conn, 0, win->id, BUTTONMASK, XCB_GRAB_MODE_SYNC,
+ XCB_GRAB_MODE_ASYNC, XCB_WINDOW_NONE, XCB_CURSOR_NONE,
+ XCB_BUTTON_INDEX_ANY, XCB_BUTTON_MASK_ANY);
}
const char *quirkname[] = {
focus_mode = SWM_FOCUS_DEFAULT;
else if (!strcmp(value, "follow_cursor"))
focus_mode = SWM_FOCUS_FOLLOW;
- else if (!strcmp(value, "synergy"))
- focus_mode = SWM_FOCUS_SYNERGY;
+ else if (!strcmp(value, "manual"))
+ focus_mode = SWM_FOCUS_MANUAL;
else
errx(1, "focus_mode");
break;
}
}
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
return (0);
}
/* Set initial _NET_WM_ALLOWED_ACTIONS */
ewmh_update_actions(win);
+ grabbuttons(win);
+
DNPRINTF(SWM_D_MISC, "manage_window: done. window: 0x%x, (x,y) w x h: "
"(%d,%d) %d x %d, ws: %d, iconic: %s, transient: 0x%x\n", win->id,
X(win), Y(win), WIDTH(win), HEIGHT(win), win->ws->idx,
{
struct ws_win *win;
int i;
- unsigned int action;
+ int handled = 0;
DNPRINTF(SWM_D_EVENT, "buttonpress: window 0x%x, detail: %u\n",
e->event, e->detail);
return;
focus_win(focus_magic(win));
- action = client_click;
for (i = 0; i < LENGTH(buttons); i++)
- if (action == buttons[i].action && buttons[i].func &&
+ if (client_click == buttons[i].action && buttons[i].func &&
buttons[i].button == e->detail &&
- CLEANMASK(buttons[i].mask) == CLEANMASK(e->state))
+ CLEANMASK(buttons[i].mask) == CLEANMASK(e->state)) {
buttons[i].func(win, &buttons[i].args);
+ handled = 1;
+ }
+
+ if (!handled) {
+ DNPRINTF(SWM_D_EVENT, "buttonpress: passing to window\n");
+ xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, e->time);
+ }
xcb_flush(conn);
}
stack_floater(win, win->ws->r);
- if (focus_mode == SWM_FOCUS_DEFAULT) {
- event_drain(XCB_ENTER_NOTIFY);
- } else {
- xcb_flush(conn);
- }
+ focus_flush();
} else {
config_win(win, e);
xcb_flush(conn);
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
#ifdef SWM_DEBUG
enternotify(xcb_enter_notify_event_t *e)
{
struct ws_win *win;
+
DNPRINTF(SWM_D_FOCUS, "enternotify: window: 0x%x, mode: %s(%d), "
"detail: %s(%d), root: 0x%x, subwindow: 0x%x, same_screen_focus: "
"%s, state: %d\n", e->event, get_notify_mode_label(e->mode),
e->mode, get_notify_detail_label(e->detail), e->detail, e->root,
e->child, YESNO(e->same_screen_focus), e->state);
- switch (focus_mode) {
- case SWM_FOCUS_DEFAULT:
- break;
- case SWM_FOCUS_FOLLOW:
- break;
- case SWM_FOCUS_SYNERGY:
- break;
+ if (focus_mode == SWM_FOCUS_MANUAL &&
+ e->mode == XCB_NOTIFY_MODE_NORMAL) {
+ DNPRINTF(SWM_D_EVENT, "enternotify: manual focus; ignoring.\n");
+ return;
}
if ((win = find_window(e->event)) == NULL) {
- DNPRINTF(SWM_D_EVENT, "skip enternotify: window is NULL\n");
+ DNPRINTF(SWM_D_EVENT, "enternotify: window is NULL; ignoring\n");
return;
}