fluxbox/src/Rootmenu.cc

141 lines
3.7 KiB
C++
Raw Normal View History

2001-12-11 20:47:02 +00:00
// Rootmenu.cc for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
2002-04-28 18:47:47 +00:00
//Use GNU extensions
2001-12-11 20:47:02 +00:00
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif // _GNU_SOURCE
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif // HAVE_CONFIG_H
#include "fluxbox.hh"
#include "Rootmenu.hh"
#include "Screen.hh"
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif // HAVE_STDIO_H
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif // STDC_HEADERS
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif // HAVE_SYS_PARAM_H
#ifndef MAXPATHLEN
#define MAXPATHLEN 255
#endif // MAXPATHLEN
Rootmenu::Rootmenu(BScreen *scrn)
: Basemenu(scrn),
auto_group_window(0)
{
2001-12-11 20:47:02 +00:00
screen = scrn;
}
2002-04-03 12:08:54 +00:00
void Rootmenu::itemSelected(int button, unsigned int index) {
2001-12-11 20:47:02 +00:00
Fluxbox *fluxbox = Fluxbox::instance();
if (button == 1) {
BasemenuItem *item = find(index);
if (item->function()) {
switch (item->function()) {
2002-01-11 09:33:33 +00:00
case BScreen::EXECUTE:
2002-04-08 22:24:50 +00:00
if (item->exec().size()) {
2001-12-11 20:47:02 +00:00
#ifndef __EMX__
char displaystring[MAXPATHLEN];
sprintf(displaystring, "DISPLAY=%s",
DisplayString(screen->getBaseDisplay()->getXDisplay()));
sprintf(displaystring + strlen(displaystring) - 1, "%d",
screen->getScreenNumber());
screen->setAutoGroupWindow(useAutoGroupWindow());
2002-04-08 22:24:50 +00:00
bexec(item->exec().c_str(), displaystring);
2001-12-11 20:47:02 +00:00
#else // __EMX__
2002-04-08 22:24:50 +00:00
spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", item->exec().c_str(), NULL);
2001-12-11 20:47:02 +00:00
#endif // !__EMX__
}
break;
2002-01-11 09:33:33 +00:00
case BScreen::RESTART:
2001-12-11 20:47:02 +00:00
fluxbox->restart();
break;
2002-01-11 09:33:33 +00:00
case BScreen::RESTARTOTHER:
2002-04-08 22:24:50 +00:00
if (item->exec().size())
fluxbox->restart(item->exec().c_str());
2001-12-11 20:47:02 +00:00
break;
2002-01-11 09:33:33 +00:00
case BScreen::EXIT:
2001-12-11 20:47:02 +00:00
fluxbox->shutdown();
2002-05-18 12:38:13 +00:00
break;
2001-12-11 20:47:02 +00:00
2002-01-11 09:33:33 +00:00
case BScreen::SETSTYLE:
2002-04-08 22:24:50 +00:00
if (item->exec().size()) {
fluxbox->saveStyleFilename(item->exec().c_str());
2002-04-28 18:47:47 +00:00
fluxbox->reconfigureTabs();
2001-12-11 20:47:02 +00:00
}
2002-04-28 18:47:47 +00:00
fluxbox->reconfigure();
2002-05-18 12:38:13 +00:00
fluxbox->save_rc();
break;
2002-01-11 09:33:33 +00:00
case BScreen::RECONFIGURE:
2001-12-11 20:47:02 +00:00
fluxbox->reconfigure();
return;
}
if (! (screen->getRootmenu()->isTorn() || isTorn()) &&
2002-01-11 09:33:33 +00:00
item->function() != BScreen::RECONFIGURE &&
item->function() != BScreen::SETSTYLE)
2001-12-11 20:47:02 +00:00
hide();
}
}
}
void Rootmenu::setAutoGroupWindow(Window window)
{
auto_group_window = window;
}
Window Rootmenu::useAutoGroupWindow()
{
// Return and clear the auto-grouping state.
Window w = auto_group_window;
if (w)
auto_group_window = 0; // clear it immediately
// If not set check the parent and the parent's parent, ...
else {
Rootmenu* parent = dynamic_cast<Rootmenu*>(GetParent());
if (parent)
w = parent->useAutoGroupWindow();
}
return w;
}