ttyname: use precomputed lengths
[nedit-bw.git] / ewmh-raise.diff
blob927d6983d2f28bc5f6998fb5c58ded067300d45d
1 From: Markus Schwarzenberg <schwarzb@ipms.fraunhofer.de>
2 Subject: EWMH raise support
4 This patch sets an EWMH hint before XMapRaised is called to raise a window
5 from within nedit (or nedit-server).
7 This is usefull for nedit in non-tabbed mode or nc when trying to
8 access/raise an already opened, but (partially) hidden nedit window,
9 especially when the "focus stealing prevention" of the window manager
10 cannot be configured to allow nedit to raise it's windows.
11 (Or more drastically: it makes nc usable again for those window managers)
13 The code for this patch is borrowed from wmctrl (1.0.7).
15 The patch is tested successfully with Fedora 9 / Metacity (Gnome).
17 ---
19 source/server.c | 7 ++++++-
20 util/misc.c | 30 ++++++++++++++++++++++++++++++
21 util/misc.h | 4 ++++
22 3 files changed, 40 insertions(+), 1 deletion(-)
24 diff --quilt old/source/server.c new/source/server.c
25 --- old/source/server.c
26 +++ new/source/server.c
27 @@ -353,6 +353,8 @@ static void processServerCommandString(c
29 else {
30 RaiseDocument(window);
31 + WmClientMsg(TheDisplay, XtWindow(window->shell),
32 + "_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0);
33 XMapRaised(TheDisplay, XtWindow(window->shell));
35 return;
36 @@ -505,8 +507,11 @@ static void processServerCommandString(c
37 if (*doCommand != '\0') {
38 RaiseDocument(window);
40 - if (!iconicFlag)
41 + if (!iconicFlag) {
42 + WmClientMsg(TheDisplay, XtWindow(window->shell),
43 + "_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0);
44 XMapRaised(TheDisplay, XtWindow(window->shell));
45 + }
47 /* Starting a new command while another one is still running
48 in the same window is not possible (crashes). */
49 diff --quilt old/util/misc.c new/util/misc.c
50 --- old/util/misc.c
51 +++ new/util/misc.c
52 @@ -891,6 +891,7 @@ void RaiseWindow(Display *display, Windo
53 XSetInputFocus(display, w, RevertToParent, CurrentTime);
56 + WmClientMsg(display, w, "_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0);
57 XMapRaised(display, w);
60 @@ -2421,3 +2422,32 @@ int SpinClipboardUnlock(Display *display
62 return res;
65 +/*
66 +** Send a client message to a EWMH/NetWM compatible X Window Manager.
67 +** Code taken from wmctrl-1.07 (GPL licensed)
68 +*/
69 +void WmClientMsg(Display *disp, Window win, const char *msg,
70 + unsigned long data0, unsigned long data1,
71 + unsigned long data2, unsigned long data3,
72 + unsigned long data4)
74 + XEvent event;
75 + long mask = SubstructureRedirectMask | SubstructureNotifyMask;
77 + event.xclient.type = ClientMessage;
78 + event.xclient.serial = 0;
79 + event.xclient.send_event = True;
80 + event.xclient.message_type = XInternAtom(disp, msg, False);
81 + event.xclient.window = win;
82 + event.xclient.format = 32;
83 + event.xclient.data.l[0] = data0;
84 + event.xclient.data.l[1] = data1;
85 + event.xclient.data.l[2] = data2;
86 + event.xclient.data.l[3] = data3;
87 + event.xclient.data.l[4] = data4;
89 + if (!XSendEvent(disp, DefaultRootWindow(disp), False, mask, &event)) {
90 + fprintf(stderr, "nedit: cannot send %s EWMH event.\n", msg);
91 + }
93 diff --quilt old/util/misc.h new/util/misc.h
94 --- old/util/misc.h
95 +++ new/util/misc.h
96 @@ -138,5 +138,9 @@ int SpinClipboardRetrieve(Display *displ
97 long *private_id);
98 int SpinClipboardLock(Display *display, Window window);
99 int SpinClipboardUnlock(Display *display, Window window);
100 +void WmClientMsg(Display *disp, Window win, const char *msg,
101 + unsigned long data0, unsigned long data1,
102 + unsigned long data2, unsigned long data3,
103 + unsigned long data4);
105 #endif /* NEDIT_MISC_H_INCLUDED */