[hackers] [wmii] [witray] Replace currently running system tray at startup. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sat, 5 Jun 2010 08:31:57 +0000 (UTC)

changeset: 2707:ac4999077666
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Sat Jun 05 04:31:46 2010 -0400
files: cmd/tray/dat.h cmd/tray/main.c cmd/tray/selection.c cmd/wmii/frame.c cmd/wmii/key.c
description:
[witray] Replace currently running system tray at startup.

diff -r 60eefd645467 -r ac4999077666 cmd/tray/dat.h
--- a/cmd/tray/dat.h Fri Jun 04 20:37:05 2010 -0400
+++ b/cmd/tray/dat.h Sat Jun 05 04:31:46 2010 -0400
@@ -51,6 +51,8 @@
         void (*cleanup)(Selection*);
         void (*message)(Selection*, XClientMessageEvent*);
         void (*request)(Selection*, XSelectionRequestEvent*);
+ long timer;
+ ulong oldowner;
 };
 
 struct XEmbed {
diff -r 60eefd645467 -r ac4999077666 cmd/tray/main.c
--- a/cmd/tray/main.c Fri Jun 04 20:37:05 2010 -0400
+++ b/cmd/tray/main.c Sat Jun 05 04:31:46 2010 -0400
@@ -69,6 +69,8 @@
 
         while(tray.clients)
                 client_disown(tray.clients);
+ tray.selection = nil;
+ srv.running = false;
 }
 
 void
@@ -181,6 +183,8 @@
                                           event_xtime, message, cleanup);
         if(tray.selection == nil)
                 fatal("Another system tray is already running.");
+ if(tray.selection->oldowner)
+ print("Replacing currently running system tray.\n");
 
         xext_init();
         tray_init();
@@ -198,7 +202,8 @@
         srv.running = true;
         ixp_serverloop(&srv);
 
- selection_release(tray.selection);
+ if(tray.selection)
+ selection_release(tray.selection);
 
         XCloseDisplay(display);
 
diff -r 60eefd645467 -r ac4999077666 cmd/tray/selection.c
--- a/cmd/tray/selection.c Fri Jun 04 20:37:05 2010 -0400
+++ b/cmd/tray/selection.c Sat Jun 05 04:31:46 2010 -0400
@@ -5,6 +5,7 @@
 #include "fns.h"
 
 static Handlers selection_handlers;
+static Handlers steal_handlers;
 
 Selection*
 selection_create(char *selection, ulong time,
@@ -47,20 +48,51 @@
         return s;
 }
 
+static void
+_selection_manage(Selection *s) {
+
+ Dprint("[selection] Notifying.\n");
+ clientmessage(&scr.root, "MANAGER", SubstructureNotifyMask|StructureNotifyMask, 32,
+ (ClientMessageData){ .l = {s->time_start, xatom(s->selection), s->owner->xid} });
+}
+
+static void
+timeout(long timer, void *v) {
+ Selection *s;
+
+ s = v;
+ Dprint("[selection] Done waiting. Killing 0x%ulx.\n", s->oldowner);
+ s->timer = 0;
+ XKillClient(display, s->oldowner);
+ sync();
+}
+
 Selection*
 selection_manage(char *selection, ulong time,
                  void (*message)(Selection*, XClientMessageEvent*),
                  void (*cleanup)(Selection*)) {
         Selection *s;
+ Window *w;
+ XWindow old;
 
- if(XGetSelectionOwner(display, xatom(selection)) != None)
- return nil;
+ if((old = XGetSelectionOwner(display, xatom(selection)))) {
+ w = emallocz(sizeof *w);
+ w->type = WWindow;
+ w->xid = old;
+ selectinput(w, StructureNotifyMask);
+ }
 
         s = selection_create(selection, time, nil, cleanup);
         if(s) {
                 s->message = message;
- clientmessage(&scr.root, "MANAGER", SubstructureNotifyMask|StructureNotifyMask, 32,
- (ClientMessageData){ .l = {time, xatom(selection), s->owner->xid} });
+ s->oldowner = old;
+ if(!old)
+ _selection_manage(s);
+ else {
+ Dprint("[selection] Waiting for old owner %W to die...\n", w);
+ pushhandler(w, &steal_handlers, s);
+ s->timer = ixp_settimer(&srv, 2000, timeout, s);
+ }
         }
 
         return s;
@@ -70,9 +102,9 @@
 selection_release(Selection *s) {
         if(!s->time_end)
                 XSetSelectionOwner(display, xatom(s->selection), None, s->time_start);
- destroywindow(s->owner);
         if(s->cleanup)
                 s->cleanup(s);
+ destroywindow(s->owner);
         free(s->selection);
         free(s);
 }
@@ -106,6 +138,7 @@
         Selection *s;
 
         USED(w, ev);
+ Dprint("[selection] Lost selection\n");
         s = aux;
         s->time_end = ev->time;
         selection_release(s);
@@ -120,6 +153,7 @@
         if(ev->property == None)
                 ev->property = ev->target; /* Per ICCCM §2.2. */
 
+ Dprint("[selection] Request: %A\n", ev->target);
         if(ev->target == xatom("TIMESTAMP")) {
                 /* Per ICCCM §2.6.2. */
                 changeprop_ulong(window(ev->requestor),
@@ -142,3 +176,21 @@
         .selectionrequest = selectionrequest_event,
 };
 
+static bool
+destroy_event(Window *w, void *aux, XDestroyWindowEvent *e) {
+ Selection *s;
+
+ Dprint("[selection] Old owner is dead.\n");
+ s = aux;
+ if(s->timer)
+ ixp_unsettimer(&srv, s->timer);
+ s->timer = 0;
+ s->oldowner = 0;
+ _selection_manage(s);
+ return false;
+}
+
+static Handlers steal_handlers = {
+ .destroy = destroy_event,
+};
+
diff -r 60eefd645467 -r ac4999077666 cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Fri Jun 04 20:37:05 2010 -0400
+++ b/cmd/wmii/frame.c Sat Jun 05 04:31:46 2010 -0400
@@ -348,8 +348,8 @@
                            || Dy(r) == 0 && (!f->area->max || resizing)
                               && !f->collapsed)) {
                 fprint(2, "Frame rect: %R\n", r);
- r.max.x = min(r.min.x+1, r.max.x);
- r.max.y = min(r.min.y+1, r.max.y);
+ r.max.x = max(r.min.x+1, r.max.x);
+ r.max.y = max(r.min.y+1, r.max.y);
         }
 
         c = f->client;
diff -r 60eefd645467 -r ac4999077666 cmd/wmii/key.c
--- a/cmd/wmii/key.c Fri Jun 04 20:37:05 2010 -0400
+++ b/cmd/wmii/key.c Sat Jun 05 04:31:46 2010 -0400
@@ -129,7 +129,7 @@
         do {
                 XMaskEvent(display, KeyPressMask, &e);
                 *mod |= e.xkey.state & valid_mask;
- *code = (KeyCode) e.xkey.keycode;
+ *code = (KeyCode)e.xkey.keycode;
                 sym = XKeycodeToKeysym(display, e.xkey.keycode, 0);
         } while(IsModifierKey(sym));
 }
@@ -143,7 +143,7 @@
         if(c == nil || c->w.xid == 0)
                 return;
 
- e.time = CurrentTime;
+ e.time = event_xtime;
         e.window = c->w.xid;
         e.state = mod;
         e.keycode = key;
Received on Sat Jun 05 2010 - 08:31:57 UTC

This archive was generated by hypermail 2.2.0 : Sat Jun 05 2010 - 08:36:03 UTC