commit d17e46ac2ede0296fe5091897751fc391cbbf018
parent b8971ed40397d82b777bdf48985687f96da5a441
Author: garbeam <garbeam@mmv.wmii.de>
Date: Tue, 27 Dec 2005 22:13:50 +0200
applied DenisG patch
Diffstat:
4 files changed, 61 insertions(+), 5 deletions(-)
diff --git a/cmd/wm/event.c b/cmd/wm/event.c
@@ -21,6 +21,7 @@ static void handle_propertynotify(XEvent * e);
static void handle_unmapnotify(XEvent * e);
static void handle_enternotify(XEvent * e);
static void handle_ignore_enternotify_crap(XEvent * e);
+static void handle_clientmessage(XEvent * e);
static unsigned int ignore_enternotify_crap = 0;
@@ -47,6 +48,7 @@ init_event_hander()
handler[PropertyNotify] = handle_propertynotify;
handler[MapNotify] = handle_ignore_enternotify_crap;
handler[UnmapNotify] = handle_unmapnotify;
+ handler[ClientMessage] = handle_clientmessage;
}
void
@@ -297,3 +299,27 @@ handle_ignore_enternotify_crap(XEvent * e)
ignore_enternotify_crap = e->xany.serial;
XSync(dpy, False);
}
+
+static void handle_clientmessage(XEvent *e)
+{
+ XClientMessageEvent *ev = &e->xclient;
+
+ if (ev->message_type == net_atoms[NET_NUMBER_OF_DESKTOPS] && ev->format == 32) {
+ return; /* ignore */
+ }
+ else if (ev->message_type == net_atoms[NET_CURRENT_DESKTOP] && ev->format == 32) {
+ int i;
+ Page *p;
+ i = ev->data.l[0];
+
+ for (p = pages; p; p = p->next) {
+ if (p->index == i) {
+ focus_page(p);
+ return;
+ }
+ }
+
+ return;
+ }
+}
+
diff --git a/cmd/wm/page.c b/cmd/wm/page.c
@@ -6,6 +6,7 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include <X11/Xatom.h>
#include "wm.h"
@@ -41,16 +42,21 @@ alloc_page()
new->floating = alloc_area(new, "float");
new->sel = new->managed = alloc_area(new, def[WM_LAYOUT]->content);
for(p = pages; p && p->next; p = p->next);
- if(!p)
+ if(!p) {
pages = new;
+ new->index = 0;
+ }
else {
new->prev = p;
p->next = new;
+ new->index = p->index + 1;
}
selpage = new;
def[WM_SEL_PAGE]->content = new->file[P_PREFIX]->content;
invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]);
npages++;
+ XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &npages, 1);
+ focus_page(new);
return new;
}
@@ -72,16 +78,25 @@ destroy_page(Page * p)
if(p->next)
p->next->prev = nil;
pages = p->next;
+ pages->index = 0;
} else {
p->prev->next = p->next;
if(p->next)
p->next->prev = p->prev;
}
- free(p);
+ free(p);
+
+ /* update page indexes */
+ for (p = pages; p && p->next; p = p->next) {
+ if (p->prev && p->prev->index + 1 != p->index) /* if page index difference is not one */
+ --(p->index);
+ }
+
if(!selpage)
selpage = pages;
npages--;
+ XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &npages, 1);
if(selpage)
focus_page(selpage);
@@ -97,6 +112,7 @@ focus_page(Page * p)
def[WM_SEL_PAGE]->content = p->file[P_PREFIX]->content;
invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]);
focus_area(sel_area());
+ XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &(selpage->index), 1);
}
XRectangle *
diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c
@@ -660,7 +660,10 @@ init_atoms()
wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
motif_wm_hints = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
- net_wm_desktop = XInternAtom(dpy, "_NET_WM_DESKTOP", False);
+ net_atoms[NET_NUMBER_OF_DESKTOPS] = XInternAtom(dpy, "_NET_NUMBER_OF_DESKTOPS", False);
+ net_atoms[NET_CURRENT_DESKTOP] = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False);
+ net_atoms[NET_WM_DESKTOP] = XInternAtom(dpy, "_NET_WM_DESKTOP", False);
+ XChangeProperty(dpy, root, XInternAtom(dpy, "_NET_SUPPORTED", False), XA_ATOM, 32, PropModeReplace, (unsigned char *) net_atoms, NET_ATOM_COUNT);
}
static void
diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h
@@ -90,6 +90,16 @@ enum {
WM_LAST
};
+/* array indexes of EWMH window properties */
+ /* TODO: set / react */
+enum {
+ NET_NUMBER_OF_DESKTOPS, /* ✓ – */
+ NET_CURRENT_DESKTOP, /* ✓ ✓ */
+ NET_WM_DESKTOP /* ✗ ✗ */
+};
+
+#define NET_ATOM_COUNT 3
+
#define PROTO_DEL 1
#define BORDER_WIDTH 3
#define LAYOUT "column"
@@ -111,6 +121,7 @@ struct Page {
File *file[P_LAST];
Page *next;
Page *prev;
+ size_t index;
};
struct Layout {
@@ -186,12 +197,12 @@ XColor xorcolor;
GC xorgc;
GC transient_gc;
-Atom wm_state;
+Atom wm_state; /* TODO: Maybe replace with wm_atoms[WM_ATOM_COUNT]? */
Atom wm_change_state;
Atom wm_protocols;
Atom wm_delete;
Atom motif_wm_hints;
-Atom net_wm_desktop;
+Atom net_atoms[NET_ATOM_COUNT];
Cursor normal_cursor;
Cursor resize_cursor;