#include <glib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <xcb/xcb.h>
return 0;
}
- while (ev = xcb_wait_for_event(conn)) {
- printf("event\n");
- switch (ev->response_type & ~0x80) {
- case XCB_CREATE_WINDOW:
+ while ((ev = xcb_wait_for_event(conn))) {
+ printf("event %d\n", ev->response_type);
+
+ if (!ev->response_type) {
+ /* XXX handle error */
+ free(ev);
+ continue;
+ }
+
+ switch (ev->response_type) {
+ case XCB_CREATE_NOTIFY:
{
- xcb_create_notify_event_t *cev = (xcb_create_notify_event_t*)ev;
- d_screen_t *sc = screen_from_root(screens, nscreens, cev->parent);
- screen_add_window(sc, cev);
+ xcb_create_notify_event_t *cev;
+ d_screen_t *sc;
+
+ cev = (xcb_create_notify_event_t*)ev;
+ sc = screen_from_root(screens, nscreens, cev->parent);
+ if (!sc) break;
+ screen_add_window(sc, cev->window);
+ break;
}
- case XCB_DESTROY_WINDOW:
+ case XCB_DESTROY_NOTIFY:
{
- xcb_destroy_notify_event_t *dev = (xcb_destroy_notify_event_t*)ev;
- d_screen_t *sc = screen_from_root(screens, nscreens, dev->event);
- d_window_t *w = screen_find_window(sc, dev->window);
- screen_hide_window(sc, w);
+ xcb_destroy_notify_event_t *dev;
+ d_screen_t *sc;
+ d_window_t *w;
+
+ dev = (xcb_destroy_notify_event_t*)ev;
+ sc = screen_from_root(screens, nscreens, dev->event);
+ if (!sc) break;
+ w = screen_find_window(sc, dev->window);
+ w->hide(w);
screen_remove_window(sc, w);
+ break;
+ }
+ case XCB_REPARENT_NOTIFY:
+ {
+ xcb_reparent_notify_event_t *rev;
+ d_screen_t *sc;
+ d_window_t *w;
+
+ rev = (xcb_reparent_notify_event_t*)ev;
+ sc = screen_from_root(screens, nscreens, rev->event);
+ if (!sc) break;
+ w = screen_find_window(sc, rev->window);
+ if (rev->parent == sc->super.root)
+ screen_add_window(sc, rev->window);
+ else {
+ w->hide(w);
+ screen_remove_window(sc, w);
+ }
+ break;
}
- case XCB_REPARENT_WINDOW:
default:
break;
}
}
void
-screen_add_window(d_screen_t *sc, xcb_create_notify_event_t *cev)
+screen_add_window(d_screen_t *sc, xcb_window_t wid)
{
d_window_t *w;
- w = window_new(cev->window, sc);
+ /* XXX xgetwindowattributes - size and tings */
+
+ w = window_new(wid, sc);
g_hash_table_insert(sc->winhash, &w->id, w);
printf("added window 0x%x\n", w->id);
return g_hash_table_lookup(sc->winhash, &id);
}
-void
-screen_show_window(d_screen_t *sc, struct d_window *w)
-{
-}
-
-void
-screen_hide_window(d_screen_t *sc, struct d_window *w)
-{
-}
-
static xcb_timestamp_t
screen_timestamp(d_screen_t *sc)
{
*/
gboolean screen_register(d_screen_t *sc);
-void screen_add_window(d_screen_t *sc, xcb_create_notify_event_t *cev);
+void screen_add_window(d_screen_t *sc, xcb_window_t wid);
void screen_remove_window(d_screen_t *sc, struct d_window *w);
struct d_window* screen_find_window(d_screen_t *sc, xcb_window_t id);
-void screen_show_window(d_screen_t *sc, struct d_window *w);
-void screen_hide_window(d_screen_t *sc, struct d_window *w);
-
#endif