#include <X11/Xlib-xcb.h>
#include <xcb/randr.h>
#include <xcb/xcb_atom.h>
+#include <xcb/xcb_aux.h>
#include <xcb/xcb_event.h>
#include <xcb/xcb_icccm.h>
#include <xcb/xcb_keysyms.h>
}
void
-drain_enter_notify(void)
-{
- int i = 0;
- XEvent cne;
-
- while (XCheckMaskEvent(display, EnterWindowMask, &cne))
- i++;
-
- DNPRINTF(SWM_D_EVENT, "drain_enter_notify: drained: %d\n", i);
-}
-
-void
set_win_state(struct ws_win *win, uint16_t state)
{
uint16_t data[2] = { state, XCB_ATOM_NONE };
free(r);
}
+ DNPRINTF(SWM_D_MISC, "getstate property: win 0x%x state %u\n", w,
+result);
return (result);
}
void
unfocus_win(struct ws_win *win)
{
- XEvent cne;
xcb_window_t none = XCB_WINDOW_NONE;
DNPRINTF(SWM_D_FOCUS, "unfocus_win: window: 0x%x\n", WINID(win));
win->ws->focus_prev = NULL;
}
- /* drain all previous unfocus events */
- while (XCheckTypedEvent(display, FocusOut, &cne) == True)
- ;
-
grabbuttons(win, 0);
xcb_change_window_attributes(conn, win->id, XCB_CW_BORDER_PIXEL,
&win->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
void
focus_win(struct ws_win *win)
{
- XEvent cne;
struct ws_win *cfw = NULL;
xcb_get_input_focus_cookie_t c;
xcb_get_input_focus_reply_t *r;
win->ws->focus = win;
if (win->ws->r != NULL) {
- /* drain all previous focus events */
- while (XCheckTypedEvent(display, FocusIn, &cne) == True)
- ;
-
if (win->java == 0)
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT,
win->id, XCB_CURRENT_TIME);
if (unmap_old)
TAILQ_FOREACH(win, &old_ws->winlist, entry)
unmap_window(win);
-
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
}
void
ws->cur_layout = &layouts[0];
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
+
a.id = SWM_ARG_ID_FOCUSCUR;
+
focus(r, &a);
}
if (font_adjusted)
font_adjusted--;
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
-
DNPRINTF(SWM_D_STACK, "stack: end\n");
}
unmap_window(r->ws->focus);
update_iconic(r->ws->focus, 1);
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
+
r->ws->focus = NULL;
a.id = SWM_ARG_ID_FOCUSCUR;
focus(r, &a);
_NET_WM_STATE_TOGGLE);
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
if (win == win->ws->focus) {
a.id = SWM_ARG_ID_FOCUSCUR;
return;
}
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
-
/* get cursor offset from window root */
xpr = xcb_query_pointer_reply(conn, xcb_query_pointer(conn, win->id),
NULL);
xcb_close_font(conn, cursor_font);
free(gpr);
free(xpr);
-
- /* drain events */
- drain_enter_notify();
}
void
xcb_free_cursor(conn, cursor);
xcb_close_font(conn, cursor_font);
xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
-
- /* drain events */
- drain_enter_notify();
}
void
adjust_font(win);
if (font_adjusted)
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
}
}
unmanage_window(win);
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
free_window(win);
}
void
enternotify(xcb_enter_notify_event_t *e)
{
- XEvent cne;
struct ws_win *win;
#if 0
struct ws_win *w;
return;
}
-#if 0
- /*
- * if we have more enternotifies let them handle it in due time
- */
- if (XCheckTypedEvent(display, EnterNotify, &cne) == True) {
- DNPRINTF(SWM_D_EVENT,
- "ignoring enternotify: got more enternotify\n");
- XPutBackEvent(display, &cne);
- return;
- }
-#endif
-
focus_magic(win);
}
unmanage_window(win);
stack();
- /* giant hack for apps that don't destroy transient windows */
- /* eat a bunch of events to prevent remanaging the window */
- XEvent cne;
- while (XCheckWindowEvent(display, e->window,
- EnterWindowMask, &cne))
- ;
- while (XCheckWindowEvent(display, e->window,
- StructureNotifyMask, &cne))
- ;
- while (XCheckWindowEvent(display, e->window,
- SubstructureNotifyMask, &cne))
- ;
/* resend unmap because we ated it */
xcb_unmap_window(conn, e->window);
}
-
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
}
void
TAILQ_FOREACH(r, &screens[i].rl, entry)
bar_setup(r);
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
}
void
if (!(display = XOpenDisplay(0)))
errx(1, "can not open display");
- if (!(conn = XGetXCBConnection(display)))
- errx(1, "can not get XCB connection");
-
- if (active_wm())
- errx(1, "other wm running");
-
/* handle some signals */
bzero(&sact, sizeof(sact));
sigemptyset(&sact.sa_mask);
sact.sa_flags = SA_NOCLDSTOP;
sigaction(SIGCHLD, &sact, NULL);
+ conn = XGetXCBConnection(display);
+ if (xcb_connection_has_error(conn))
+ errx(1, "can not get XCB connection");
+
+ xfd = xcb_get_file_descriptor(conn);
+ syms = xcb_key_symbols_alloc(conn);
+ if (!syms)
+ errx(1, "unable to allocate key symbols");
+
astate = get_atom_from_string("WM_STATE");
aprot = get_atom_from_string("WM_PROTOCOLS");
adelete = get_atom_from_string("WM_DELETE_WINDOW");
if (pwd == NULL)
errx(1, "invalid user: %d", getuid());
- syms = xcb_key_symbols_alloc(conn);
- if (syms == NULL)
- errx(1, "unable to allocate key symbols");
+ xcb_grab_server(conn);
+ xcb_aux_sync(conn);
+ /* flush all events */
+ while ((evt = xcb_poll_for_event(conn))) {
+ uint8_t type = XCB_EVENT_RESPONSE_TYPE(evt);
+ if (type == 0)
+ event_handle(evt);
+ free(evt);
+ }
+
+ if (active_wm())
+ errx(1, "other wm running");
+
+ xcb_aux_sync(conn);
+
setup_globals();
setup_screens();
setup_keys();
bar_setup(r);
}
- unfocus_all();
+ //unfocus_all();
grabkeys();
stack();
- if (focus_mode == SWM_FOCUS_DEFAULT)
- drain_enter_notify();
- xfd = xcb_get_file_descriptor(conn);
+ xcb_ungrab_server(conn);
+ xcb_flush(conn);
+
while (running) {
while ((evt = xcb_poll_for_event(conn))) {
if (running == 0)