From 05ba7f4bb66ccc4f63b723f8e0223c4ba0fe3f39 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Mon, 5 Jul 2010 06:23:59 +0000 Subject: [PATCH] EWMH raise support From: Markus Schwarzenberg This patch sets an EWMH hint before XMapRaised is called to raise a window from within nedit (or nedit-server). This is usefull for nedit in non-tabbed mode or nc when trying to access/raise an already opened, but (partially) hidden nedit window, especially when the "focus stealing prevention" of the window manager cannot be configured to allow nedit to raise it's windows. (Or more drastically: it makes nc usable again for those window managers) The code for this patch is borrowed from wmctrl (1.0.7). The patch is tested successfully with Fedora 9 / Metacity (Gnome). SourceForge-patch-Id: 2337783 --- ReleaseNotes | 5 ++++- source/server.c | 9 +++++++-- util/misc.c | 32 +++++++++++++++++++++++++++++++- util/misc.h | 6 +++++- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/ReleaseNotes b/ReleaseNotes index fcb9d6c..98425b2 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -1,7 +1,7 @@ Release Notes for NEdit Version 5.5, October 2004 -$Id: ReleaseNotes,v 1.67 2009/09/14 19:18:23 edg Exp $ +$Id: ReleaseNotes,v 1.68 2010/07/05 06:23:59 lebert Exp $ This file contains last minute notes to users about the release, which are not included in the documentation or README files included with the distribution @@ -23,6 +23,9 @@ New Features in $NEXT_VERSION Bugs fixed in $NEXT_VERSION + - Fix raising of windows from within nedit (e.g. when opening an already + opened document with nc). Patch is SF patch #2337783. + - Fix for SF bug #2858723: off-by-one error causing a crash - Fix for SF bug #2687525: tipsfile parser error wrt to eof diff --git a/source/server.c b/source/server.c index a6b78a2..61b89fb 100644 --- a/source/server.c +++ b/source/server.c @@ -1,4 +1,4 @@ -static const char CVSID[] = "$Id: server.c,v 1.34 2007/12/31 11:12:43 yooden Exp $"; +static const char CVSID[] = "$Id: server.c,v 1.35 2010/07/05 06:23:59 lebert Exp $"; /******************************************************************************* * * * server.c -- Nirvana Editor edit-server component * @@ -361,6 +361,8 @@ static void processServerCommandString(char *string) } else { RaiseDocument(window); + WmClientMsg(TheDisplay, XtWindow(window->shell), + "_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0); XMapRaised(TheDisplay, XtWindow(window->shell)); } return; @@ -495,8 +497,11 @@ static void processServerCommandString(char *string) if (*doCommand != '\0') { RaiseDocument(window); - if (!iconicFlag) + if (!iconicFlag) { + WmClientMsg(TheDisplay, XtWindow(window->shell), + "_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0); XMapRaised(TheDisplay, XtWindow(window->shell)); + } /* Starting a new command while another one is still running in the same window is not possible (crashes). */ diff --git a/util/misc.c b/util/misc.c index 8807082..6f5989d 100644 --- a/util/misc.c +++ b/util/misc.c @@ -1,4 +1,4 @@ -static const char CVSID[] = "$Id: misc.c,v 1.88 2008/01/04 22:11:05 yooden Exp $"; +static const char CVSID[] = "$Id: misc.c,v 1.89 2010/07/05 06:23:59 lebert Exp $"; /******************************************************************************* * * * misc.c -- Miscelaneous Motif convenience functions * @@ -887,6 +887,7 @@ void RaiseWindow(Display *display, Window w, Boolean focus) XSetInputFocus(display, w, RevertToParent, CurrentTime); } + WmClientMsg(display, w, "_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0); XMapRaised(display, w); } @@ -2376,3 +2377,32 @@ int SpinClipboardUnlock(Display *display, Window window) */ return res; } + +/* +** Send a client message to a EWMH/NetWM compatible X Window Manager. +** Code taken from wmctrl-1.07 (GPL licensed) +*/ +void WmClientMsg(Display *disp, Window win, const char *msg, + unsigned long data0, unsigned long data1, + unsigned long data2, unsigned long data3, + unsigned long data4) +{ + XEvent event; + long mask = SubstructureRedirectMask | SubstructureNotifyMask; + + event.xclient.type = ClientMessage; + event.xclient.serial = 0; + event.xclient.send_event = True; + event.xclient.message_type = XInternAtom(disp, msg, False); + event.xclient.window = win; + event.xclient.format = 32; + event.xclient.data.l[0] = data0; + event.xclient.data.l[1] = data1; + event.xclient.data.l[2] = data2; + event.xclient.data.l[3] = data3; + event.xclient.data.l[4] = data4; + + if (!XSendEvent(disp, DefaultRootWindow(disp), False, mask, &event)) { + fprintf(stderr, "nedit: cannot send %s EWMH event.\n", msg); + } +} diff --git a/util/misc.h b/util/misc.h index 4955e34..da1b891 100644 --- a/util/misc.h +++ b/util/misc.h @@ -1,4 +1,4 @@ -/* $Id: misc.h,v 1.30 2008/01/04 22:11:05 yooden Exp $ */ +/* $Id: misc.h,v 1.31 2010/07/05 06:23:59 lebert Exp $ */ /******************************************************************************* * * * misc.h -- Nirvana Editor Miscellaneous Header File * @@ -138,5 +138,9 @@ int SpinClipboardRetrieve(Display *display, Window window, char *format_name, long *private_id); int SpinClipboardLock(Display *display, Window window); int SpinClipboardUnlock(Display *display, Window window); +void WmClientMsg(Display *disp, Window win, const char *msg, + unsigned long data0, unsigned long data1, + unsigned long data2, unsigned long data3, + unsigned long data4); #endif /* NEDIT_MISC_H_INCLUDED */ -- 2.11.4.GIT