On Wednesday 13 August 2003 13:00, Dave Serls wrote:
> I'd like to add a 'feature' to my home version (0.65) of blackbox, but
> I'm non-compis-C++ I'm afraid.
> When the 'exit' menu item is taken in Rootmenu.cc, I would like to
> scan through the list of windows looking for certain titles (the only
> identification that I know of) and, either
> (1) Issue an xmessage indicating that they are still running and that
> the session exit will not be taken; or,
> (2) actually send a close to those windows ( those windows should accept
> close, of course ).
> I should not be messing with the code, of course, seeing as I know almost
> nothing about C++, not even enough to search the Blackboxwindow list.
> I could make my own 'special' window list at create-time, I suppose.
>
> Thanks for any suggestions, clues.
>
Enclosed is a rather quicky and stupid implementation. That's what you get
for 15 minutes of hacking (-:
I used system() to implement the script calling. This has good sides and bad
sides.
Good:
you can put anything in the command string, I tested it with
'[exithook] (Exit test3) {DISPLAY=":0" xlsclients | grep -qv bob}'
Bad:
You can *NOT* run any commands which open a X window from this hook. If you
do blackbox will hang forever. You see, system() blocks the parent until it
exists. So blackbox is not awake to notice your window's request. To make
it so a window could be opened we would have to separate from the child (like
we do with a normal menu execute) and then wait for the child's return
status. Which is not that much harder, I just did not take the time to code
it. With this example someone should be able to add that in short order.
If the script exits with a 0 exit code (shell success) Blackbox exits.
Otherwise it keeps running. If you want the inverse just change the
'if (WEXITSTATUS(ret) == 0)' line to a !=.
Long term blackbox needs a way to open a dialog box internally. Then the code
could do:
if we decide not to exit:
open_dialog text="Decided not to exit after all"
As an added bonus this small patch explains how to add a new menu entry type
to the menu code (-:
Index: src/Rootmenu.cc
===================================================================
RCS file: /cvsroot/blackboxwm/blackbox/src/Rootmenu.cc,v
retrieving revision 1.22
diff -u -r1.22 Rootmenu.cc
--- src/Rootmenu.cc 16 Apr 2003 00:50:25 -0000 1.22
+++ src/Rootmenu.cc 13 Aug 2003 22:19:31 -0000
@@ -74,6 +74,13 @@
_bscreen->getBlackbox()->quit();
break;
+ case BScreen::ExitHook: {
+ int ret = system(it->second.string.c_str());
+ if (WEXITSTATUS(ret) == 0)
+ _bscreen->getBlackbox()->quit();
+ }
+ break;
+
case BScreen::SetStyle:
if (! it->second.string.empty())
_bscreen->getBlackbox()->resource().saveStyleFilename(it->second.string);
Index: src/Screen.cc
===================================================================
RCS file: /cvsroot/blackboxwm/blackbox/src/Screen.cc,v
retrieving revision 1.194
diff -u -r1.194 Screen.cc
--- src/Screen.cc 26 Jun 2003 09:03:31 -0000 1.194
+++ src/Screen.cc 13 Aug 2003 22:19:32 -0000
@@ -1053,6 +1053,18 @@
break;
}
+ case 875: { // exithook
+ if (! (*label && *command)) {
+ fprintf(stderr, bt::i18n(ScreenSet, ScreenEXECError,
+ "BScreen::parseMenuFile: [exec] error, "
+ "no menu label and/or command defined\n"));
+ continue;
+ }
+
+ menu->insertFunction(label, BScreen::ExitHook, command);
+ }
+ break;
+
case 995: // stylesdir
case 1113: { // stylesmenu
bool newmenu = ((key == 1113) ? True : False);
Index: src/Screen.hh
===================================================================
RCS file: /cvsroot/blackboxwm/blackbox/src/Screen.hh,v
retrieving revision 1.92
diff -u -r1.92 Screen.hh
--- src/Screen.hh 28 Apr 2003 14:21:26 -0000 1.92
+++ src/Screen.hh 13 Aug 2003 22:19:32 -0000
@@ -108,9 +108,9 @@
public:
enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
- enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure,
- WindowShade, WindowIconify, WindowMaximize, WindowClose, WindowRaise,
- WindowLower, WindowKill, SetStyle };
+ enum { Restart = 1, RestartOther, Exit, ExitHook, Shutdown, Execute,
+ Reconfigure, WindowShade, WindowIconify, WindowMaximize, WindowClose,
+ WindowRaise, WindowLower, WindowKill, SetStyle };
enum FocusModel { SloppyFocus, ClickToFocus };
BScreen(Blackbox *bb, unsigned int scrn);
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
List archives: http://asgardsrealm.net/lurker/splash/index.html
Trouble? Contact [EMAIL PROTECTED]