#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 *);
#ifdef SWM_DEBUG
void focusin(xcb_focus_in_event_t *);
#ifdef SWM_DEBUG
void leavenotify(xcb_leave_notify_event_t *);
#endif
+void load_float_geom(struct ws_win *, struct swm_region *);
void map_window_raised(xcb_window_t);
void mapnotify(xcb_map_notify_event_t *);
void mappingnotify(xcb_mapping_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
win->g = win->ws->r->g;
win->bordered = 0;
} else {
- if (win->g_floatvalid) {
- /* refloat at last floating relative position */
- win->g = win->g_float;
- X(win) += X(win->ws->r);
- Y(win) += Y(win->ws->r);
- }
+ load_float_geom(win, win->ws->r);
}
return (1);
/* clear back buffer */
gcv[0] = r->s->c[SWM_S_COLOR_BAR].pixel;
xcb_change_gc(conn, r->s->bar_gc, XCB_GC_FOREGROUND, gcv);
- xcb_poly_fill_rectangle(conn, r->bar->buffer, r->s->bar_gc,
- sizeof(rect), &rect);
+ xcb_poly_fill_rectangle(conn, r->bar->buffer, r->s->bar_gc, 1, &rect);
/* draw back buffer */
gcvd.graphics_exposures = 0;
/* clear back buffer */
gcv[0] = r->s->c[SWM_S_COLOR_BAR].pixel;
xcb_change_gc(conn, r->s->bar_gc, XCB_GC_FOREGROUND, gcv);
- xcb_poly_fill_rectangle(conn, r->bar->buffer, r->s->bar_gc,
- sizeof(rect), &rect);
+ xcb_poly_fill_rectangle(conn, r->bar->buffer, r->s->bar_gc, 1, &rect);
/* draw back buffer */
draw = XftDrawCreate(display, r->bar->buffer,
/* must be after stack */
bar_update();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- event_drain(XCB_ENTER_NOTIFY);
- else
- xcb_flush(conn);
+ focus_flush();
}
void
}
if ((cfw = find_window(cur_focus)) != NULL)
unfocus_win(cfw);
- else {
-#if 0
- /* use larger hammer since the window was killed somehow */
- TAILQ_FOREACH(cfw, &win->ws->winlist, entry)
- if (cfw->ws && cfw->ws->r && cfw->ws->r->s)
- xcb_change_window_attributes(conn, cfw->id,
- XCB_CW_BORDER_PIXEL,
- &cfw->ws->r->s->c[SWM_S_COLOR_UNFOCUS].pixel);
-#endif
- }
win->ws->focus = win;
{
xcb_generic_event_t *evt;
- xcb_flush(conn);
+ /* ensure all pending requests have been processed before filtering. */
+ xcb_aux_sync(conn);
while ((evt = xcb_poll_for_event(conn))) {
if (XCB_EVENT_RESPONSE_TYPE(evt) != rt)
event_handle(evt);
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
void
store_float_geom(struct ws_win *win, struct swm_region *r)
{
+ if (win == NULL || r == NULL)
+ return;
+
/* retain window geom and region geom */
win->g_float = win->g;
win->g_float.x -= X(r);
win->g_float.w, win->g_float.h);
}
+void
+load_float_geom(struct ws_win *win, struct swm_region *r)
+{
+ if (win == NULL || r == NULL)
+ return;
+
+ if (win->g_floatvalid) {
+ win->g = win->g_float;
+ X(win) += X(r);
+ Y(win) += Y(r);
+ DNPRINTF(SWM_D_MISC, "load_float_geom: window: 0x%x, g: (%d,%d)"
+ "%d x %d\n", win->id, X(win), Y(win), WIDTH(win),
+ HEIGHT(win));
+ } else {
+ DNPRINTF(SWM_D_MISC, "load_float_geom: window: 0x%x, g_float "
+ "is not set.\n", win->id);
+ }
+}
+
void
stack_floater(struct ws_win *win, struct swm_region *r)
{
* to allow windows to change their size (e.g. mplayer fs) only retrieve
* geom on ws switches or return from max mode
*/
- if (win->g_floatvalid && (win->floatmaxed || (r != r->ws->old_r &&
- !(win->ewmh_flags & EWMH_F_FULLSCREEN)))) {
- /* refloat at last floating relative position */
- win->g = win->g_float;
- X(win) += X(r);
- Y(win) += Y(r);
+ if (win->floatmaxed || (r != r->ws->old_r &&
+ !(win->ewmh_flags & EWMH_F_FULLSCREEN))) {
+ /* update geometry for the new region */
+ load_float_geom(win, r);
}
win->floatmaxed = 0;
if (!win->g_floatvalid)
store_float_geom(win, win->ws->r);
- win->g = win->ws->r->g;
+ win->g = r->g;
}
/*
HEIGHT(win) = (double)HEIGHT(r) * dialog_ratio;
}
- if (!win->manual) {
+ if (!win->manual && !(win->ewmh_flags & EWMH_F_FULLSCREEN) &&
+ !(win->quirks & SWM_Q_ANYWHERE)) {
/*
- * floaters and transients are auto-centred unless moved
- * or resized
+ * floaters and transients are auto-centred unless moved,
+ * resized or ANYWHERE quirk is set.
*/
X(win) = X(r) + (WIDTH(r) - WIDTH(win)) / 2 - BORDER(win);
Y(win) = Y(r) + (HEIGHT(r) - HEIGHT(win)) / 2 - BORDER(win);
+
+ store_float_geom(win, r);
}
/* keep window within region bounds */
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 *
}
win->floating = 0;
} else {
- if (win->g_floatvalid) {
- /* refloat at last floating relative position */
- X(win) = win->g_float.x + X(r);
- Y(win) = win->g_float.y + Y(r);
- WIDTH(win) = win->g_float.w;
- HEIGHT(win) = win->g_float.h;
- }
+ load_float_geom(win, r);
win->floating = 1;
}
if (win == NULL)
return;
+ if (win->ewmh_flags & EWMH_F_FULLSCREEN)
+ return;
+
ewmh_update_win_state(win, ewmh[_NET_WM_STATE_ABOVE].atom,
_NET_WM_STATE_TOGGLE);
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);
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);
}
X(win) = win->wa->x + win->wa->border_width;
Y(win) = win->wa->y + win->wa->border_width;
win->bordered = 0;
- win->g_floatvalid = 0;
win->floatmaxed = 0;
win->ewmh_flags = 0;
win->s = r->s; /* this never changes */
+ store_float_geom(win, r);
+
/* Get WM_SIZE_HINTS. */
xcb_icccm_get_wm_normal_hints_reply(conn,
xcb_icccm_get_wm_normal_hints(conn, win->id),
/* java is retarded so treat it special */
if (strstr(win->ch.instance_name, "sun-awt")) {
+ DNPRINTF(SWM_D_CLASS, "manage_window: java window "
+ "detected.\n");
win->java = 1;
border_me = 1;
}
fake_keypress(win, XK_KP_Add, XCB_MOD_MASK_SHIFT);
}
- /* Make sure window is positioned inside its region, if its active. */
- if (win->ws->r)
- constrain_window(win, win->ws->r, 0);
-
if (border_me) {
win->bordered = 1;
X(win) -= border_width;
Y(win) -= border_width;
}
+ /* Make sure window is positioned inside its region, if its active. */
+ if (win->ws->r)
+ constrain_window(win, win->ws->r, 0);
+
if (win->ws->r || border_me)
update_window(win);
event_mask |= XCB_EVENT_MASK_LEAVE_WINDOW;
#endif
- xcb_change_window_attributes(conn, id, XCB_CW_EVENT_MASK, &event_mask);
+ xcb_change_window_attributes(conn, win->id, XCB_CW_EVENT_MASK,
+ &event_mask);
out:
/* Figure out where to stack the window in the workspace. */
configurerequest(xcb_configure_request_event_t *e)
{
struct ws_win *win;
+ struct swm_region *r = NULL;
int new = 0, i = 0;
uint16_t mask = 0;
uint32_t wc[7] = {0};
if ((win = find_window(e->window)) == NULL)
if ((win = find_unmanaged_window(e->window)) == NULL)
new = 1;
+
#ifdef SWM_DEBUG
if (swm_debug & SWM_D_EVENT) {
print_win_geom(e->window);
xcb_configure_window(conn, e->window, mask, wc);
} else if ((!win->manual || win->quirks & SWM_Q_ANYWHERE) &&
!(win->ewmh_flags & EWMH_F_FULLSCREEN)) {
- if (e->value_mask & XCB_CONFIG_WINDOW_X) {
- win->g_float.x = e->x;
- if (win->ws->r)
- win->g_float.x -= X(win->ws->r);
- else if (win->ws->old_r)
- win->g_float.x -= X(win->ws->old_r);
- }
+ if (win->ws->r)
+ r = win->ws->r;
+ else if (win->ws->old_r)
+ r = win->ws->old_r;
+
+ /* windows are centered unless ANYWHERE quirk is set. */
+ if (win->quirks & SWM_Q_ANYWHERE) {
+ if (e->value_mask & XCB_CONFIG_WINDOW_X) {
+ win->g_float.x = e->x;
+ if (r)
+ win->g_float.x -= X(r);
+ }
- if (e->value_mask & XCB_CONFIG_WINDOW_Y) {
- win->g_float.y = e->y;
- if (win->ws->r)
- win->g_float.y -= Y(win->ws->r);
- else if (win->ws->old_r)
- win->g_float.y -= Y(win->ws->old_r);
+ if (e->value_mask & XCB_CONFIG_WINDOW_Y) {
+ win->g_float.y = e->y;
+ if (r)
+ win->g_float.y -= Y(r);
+ }
}
if (e->value_mask & XCB_CONFIG_WINDOW_WIDTH)
win->g_floatvalid = 1;
- if (win->floating && win->ws->r) {
- /* window is visible and floating; update position. */
- win->g = win->g_float;
- X(win) += X(win->ws->r);
- Y(win) += Y(win->ws->r);
+ if (win->floating && r) {
+ WIDTH(win) = win->g_float.w;
+ HEIGHT(win) = win->g_float.h;
+
+ stack_floater(win, win->ws->r);
- update_window(win);
+ focus_flush();
} else {
config_win(win, e);
+ xcb_flush(conn);
}
} else {
config_win(win, e);
+ xcb_flush(conn);
}
-
- xcb_flush(conn);
}
void
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);
-#if 0
- if (e->mode != XCB_NOTIFY_MODE_NORMAL) {
- DNPRINTF(SWM_D_EVENT, "skip enternotify: generated by "
- "cursor grab.\n");
+ if (focus_mode == SWM_FOCUS_MANUAL &&
+ e->mode == XCB_NOTIFY_MODE_NORMAL) {
+ DNPRINTF(SWM_D_EVENT, "enternotify: manual focus; ignoring.\n");
return;
}
-#endif
-
- switch (focus_mode) {
- case SWM_FOCUS_DEFAULT:
- break;
- case SWM_FOCUS_FOLLOW:
- break;
- case SWM_FOCUS_SYNERGY:
- break;
- }
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;
}
int i, num_screens;
xcb_atom_t netwmcheck;
xcb_window_t root, win;
- uint32_t wa[2];
/* work around sun jdk bugs, code from wmname */
netwmcheck = get_atom_from_string("_NET_SUPPORTING_WM_CHECK");
root = screens[i].root;
win = xcb_generate_id(conn);
- wa[0] = screens[i].c[SWM_S_COLOR_UNFOCUS].pixel;
- wa[1] = screens[i].c[SWM_S_COLOR_UNFOCUS].pixel;
- xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, 0, 0, 0, 1,
- 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT,
- XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL, wa);
+ xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, root,
+ 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ XCB_COPY_FROM_PARENT, 0, NULL);
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
netwmcheck, XCB_ATOM_WINDOW, 32, 1, &win);