From 656a3457de5c338c03b2960811d5036de47e4a80 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 3 Mar 2008 00:22:31 -0500 Subject: [PATCH] windows are added and created on create/destroy/reparent --- dcompmgr.c | 62 ++++++++++++++++++++++++++++++++++++++++++------------ screen.c | 16 ++++---------- screen.h | 5 +---- window.c | 18 ++++++++++++++++ window.h | 4 ++++ 5 files changed, 76 insertions(+), 29 deletions(-) diff --git a/dcompmgr.c b/dcompmgr.c index db14b2d..9126010 100644 --- a/dcompmgr.c +++ b/dcompmgr.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -63,24 +64,59 @@ main(int argc, char **argv) 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; } diff --git a/screen.c b/screen.c index 684d6c5..5ffae1f 100644 --- a/screen.c +++ b/screen.c @@ -100,11 +100,13 @@ screen_init(d_screen_t *sc) } 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); @@ -125,16 +127,6 @@ screen_find_window(d_screen_t *sc, xcb_window_t 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) { diff --git a/screen.h b/screen.h index 20daed3..4abfcb7 100644 --- a/screen.h +++ b/screen.h @@ -23,12 +23,9 @@ typedef struct d_screen { */ 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 diff --git a/window.c b/window.c index 3e83634..269b60d 100644 --- a/window.c +++ b/window.c @@ -1,6 +1,9 @@ #include "window.h" #include +static void window_show(d_window_t *w); +static void window_hide(d_window_t *w); + d_window_t* window_new(xcb_window_t id, struct d_screen *sc) { @@ -10,6 +13,11 @@ window_new(xcb_window_t id, struct d_screen *sc) w->id = id; w->ref = 1; w->sc = sc; + + /* default functions */ + w->show = window_show; + w->hide = window_hide; + return w; } @@ -26,3 +34,13 @@ window_unref(d_window_t *w) g_free(w); } } + +static void +window_show(d_window_t *w) +{ +} + +static void +window_hide(d_window_t *w) +{ +} diff --git a/window.h b/window.h index 5b0d9ae..e03623b 100644 --- a/window.h +++ b/window.h @@ -9,6 +9,9 @@ typedef struct d_window { xcb_window_t id; int ref; struct d_screen *sc; + + void (*show)(struct d_window *w); + void (*hide)(struct d_window *w); } d_window_t; d_window_t* window_new(xcb_window_t id, struct d_screen *sc); @@ -16,4 +19,5 @@ d_window_t* window_new(xcb_window_t id, struct d_screen *sc); void window_ref(d_window_t *w); void window_unref(d_window_t *w); + #endif -- 2.34.1