It takes the output from a command specified and parses it as a submenu. If the process outputs no text, openbox will use the old value. This is to provide some amount of caching for processes that might take time to complete. The subprocess should be as quick as possible to reduce lag.
directory\n
$ #STYLESDIRErrorNoExist
# BScreen::parseMenuFile: [stylesdir/stylesmenu] error, '%s' does not exist\n
+$ #PIPEError
+# BScreen::parseMenuFile: [pipe] error, no command defined\n
$ #WORKSPACESError
# BScreen::parseMenuFile: [workspaces] error, no menu label defined\n
$ #PositionLength
Basemenu::~Basemenu(void) {
- XUnmapWindow(display, menu.window);
+ clearMenu();
+
+ blackbox->removeMenuSearch(menu.title);
+ XDestroyWindow(display, menu.title);
+
+ blackbox->removeMenuSearch(menu.frame);
+ XDestroyWindow(display, menu.frame);
+
+ blackbox->removeMenuSearch(menu.window);
+ XDestroyWindow(display, menu.window);
+
+ if (menu.title_pixmap)
+ image_ctrl->removeImage(menu.title_pixmap);
+
+ if (menu.frame_pixmap)
+ image_ctrl->removeImage(menu.frame_pixmap);
+
+ if (menu.hilite_pixmap)
+ image_ctrl->removeImage(menu.hilite_pixmap);
+}
+
+void Basemenu::clearMenu(void) {
+ XUnmapWindow(display, menu.window);
if (shown && shown->getWindowID() == getWindowID())
shown = (Basemenu *) 0;
}
std::for_each(menuitems.begin(), menuitems.end(), PointerAssassin());
-
- if (menu.title_pixmap)
- image_ctrl->removeImage(menu.title_pixmap);
-
- if (menu.frame_pixmap)
- image_ctrl->removeImage(menu.frame_pixmap);
-
- if (menu.hilite_pixmap)
- image_ctrl->removeImage(menu.hilite_pixmap);
-
- blackbox->removeMenuSearch(menu.title);
- XDestroyWindow(display, menu.title);
-
- blackbox->removeMenuSearch(menu.frame);
- XDestroyWindow(display, menu.frame);
-
- blackbox->removeMenuSearch(menu.window);
- XDestroyWindow(display, menu.window);
+ menuitems.clear();
}
return menuitems.size();
}
-
void Basemenu::update(void) {
const MenuStyle* const style = screen->getMenuStyle();
menu.item_h = (style->f_font->height() < 9 ? 9 : style->f_font->height()) +
parent->drawSubmenu(parent->which_sub);
XMapSubwindows(display, menu.window);
+ if (visible)
+ XMapWindow(display, menu.window);
}
}
}
-
void Basemenu::hide(void) {
if (! torn && hide_tree && parent && parent->isVisible()) {
Basemenu *p = parent;
style->t_text, text);
}
-
void Basemenu::drawSubmenu(int index) {
BasemenuItem *item = find(which_sub);
if (item && item->submenu() && ! item->submenu()->isTorn() &&
if (alignment == AlignBottom &&
(y + submenu->menu.height) > ((shifted) ? menu.y_shift :
- menu.y) + menu.height)
+ menu.y) + menu.height)
y = (((shifted) ? menu.y_shift : menu.y) +
menu.height - submenu->menu.height);
submenu->move(x, y);
if (! moving) drawItem(index, True);
-
+
+ which_sub = index;
if (! submenu->isVisible())
submenu->show();
submenu->moving = moving;
- which_sub = index;
} else {
which_sub = -1;
}
BImageControl *image_ctrl;
BScreen *screen;
- bool moving, visible, movable, torn, internal_menu, title_vis, shifted,
+ bool moving, movable, torn, internal_menu, title_vis, shifted,
hide_tree;
Display *display;
int which_sub, which_press, which_sbl, alignment;
Basemenu& operator=(const Basemenu&);
protected:
+ bool visible;
+
inline void setTitleVisibility(bool b) { title_vis = b; }
inline void setMovable(bool b) { movable = b; }
inline void setHideTree(bool h) { hide_tree = h; }
unsigned int w = 0, unsigned int h = 0);
virtual void redrawTitle(void);
virtual void internal_hide(void);
-
+ inline Basemenu* getParent(void) const { return parent; }
public:
Basemenu(BScreen *scrn);
virtual ~Basemenu(void);
+ void clearMenu(void);
inline bool isTorn(void) const { return torn; }
inline bool isVisible(void) const { return visible; }
bin_PROGRAMS= openbox
-openbox_SOURCES=BaseDisplay.cc Basemenu.cc Clientmenu.cc Color.cc Configmenu.cc Configuration.cc Font.cc GCCache.cc Iconmenu.cc Image.cc ImageControl.cc Netizen.cc Rootmenu.cc Screen.cc Slit.cc Texture.cc Timer.cc Toolbar.cc Util.cc Window.cc Windowmenu.cc Workspace.cc Workspacemenu.cc XAtom.cc blackbox.cc i18n.cc main.cc
+openbox_SOURCES=BaseDisplay.cc Basemenu.cc Clientmenu.cc Color.cc Configmenu.cc Configuration.cc Font.cc GCCache.cc Iconmenu.cc Image.cc ImageControl.cc Netizen.cc Pipemenu.cc Rootmenu.cc Screen.cc Slit.cc Texture.cc Timer.cc Toolbar.cc Util.cc Window.cc Windowmenu.cc Workspace.cc Workspacemenu.cc XAtom.cc blackbox.cc i18n.cc main.cc
openbox_LDFLAGS=@XFT_LIBS@
-EXTRA_DIST = BaseDisplay.hh Basemenu.hh Clientmenu.hh Color.hh Configmenu.hh Configuration.hh Font.hh GCCache.hh Iconmenu.hh Image.hh Netizen.hh Rootmenu.hh Screen.hh Slit.hh Texture.hh Timer.hh Toolbar.hh Util.hh Window.hh Windowmenu.hh Workspace.hh Workspacemenu.hh XAtom.hh blackbox.hh i18n.hh
+EXTRA_DIST = BaseDisplay.hh Basemenu.hh Clientmenu.hh Color.hh Configmenu.hh Configuration.hh Font.hh GCCache.hh Iconmenu.hh Image.hh Netizen.hh Pipemenu.hh Rootmenu.hh Screen.hh Slit.hh Texture.hh Timer.hh Toolbar.hh Util.hh Window.hh Windowmenu.hh Workspace.hh Workspacemenu.hh XAtom.hh blackbox.hh i18n.hh
MAINTAINERCLEANFILES= Makefile.in
--- /dev/null
+// -*- mode: C++; indent-tabs-mode: nil; -*-
+// Pipemenu.cc for Openbox - an X11 Window manager
+// Copyright (c) 2002 Scott Moynes <smoynes@nexus.carleton.ca>
+//
+// 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.
+
+#ifdef HAVE_CONFIG_H
+# include "../config.h"
+#endif // HAVE_CONFIG_H
+
+extern "C" {
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
+#endif // HAVE_STDIO_H
+
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif // HAVE_STDLIB_H
+
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif // HAVE_STRING_H
+
+#ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif // HAVE_SYS_PARAM_H
+}
+
+#include "blackbox.hh"
+#include "Pipemenu.hh"
+#include "Screen.hh"
+#include "Util.hh"
+
+
+Pipemenu::Pipemenu(BScreen *scrn, const string& command) : Rootmenu(scrn),
+ _command(command){ }
+
+bool Pipemenu::readPipe() {
+ FILE* file = popen(_command.c_str(), "r");
+
+ if (file != NULL)
+ {
+ printf("popen %s\n", _command.c_str());
+ getScreen()->parseMenuFile(file, this);
+ pclose(file);
+ return true;
+ }
+ else
+ {
+ perror("bummy");
+ return false;
+ }
+}
+
+void Pipemenu::show(void) {
+ printf("%s\n", __PRETTY_FUNCTION__);
+ readPipe();
+ update();
+ visible = true;
+ getParent()->drawSubmenu(getParent()->getCurrentSubmenu());
+ Rootmenu::show();
+}
--- /dev/null
+// -*- mode: C++; indent-tabs-mode: nil; -*-
+// Pipemenu.hh for Openbox - an X11 Window manager
+// Copyright (c) 2002 Scott Moynes <smoynes@nexus.carleton.ca>
+//
+// 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.
+
+#ifndef __Pipemenu_hh
+#define __Pipemenu_hh
+
+// forward declarations
+class BScreen;
+
+#include <string>
+using std::string;
+
+#include "Rootmenu.hh"
+
+class Pipemenu : public Rootmenu {
+private:
+ Pipemenu(const Pipemenu&);
+ Pipemenu& operator=(const Pipemenu&);
+
+public:
+ Pipemenu(BScreen *scrn, const string& command);
+ //virtual void update(void);
+ virtual void show(void);
+ bool readPipe();
+private:
+ string _command;
+};
+
+
+#endif // __Pipemenu_hh
+
#include "Image.hh"
#include "Screen.hh"
#include "Slit.hh"
+#include "Pipemenu.hh"
#include "Rootmenu.hh"
#include "Toolbar.hh"
#include "Util.hh"
bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
char line[1024], keyword[1024], label[1024], command[1024];
- bool done = False;
+ bool done = False, readData = False;
while (! (done || feof(file))) {
memset(line, 0, 1024);
if (! fgets(line, 1024, file))
continue;
+ if (! readData) {
+ menu->clearMenu();
+ readData = True;
+ }
+
if (line[0] == '#') // comment, skip it
continue;
pos = string_within('{', '}', line, pos, line_length, command);
switch (key) {
- case 311: // end
+ case 'e'+'n'+'d': // end
done = True;
break;
- case 333: // nop
+ case 'n'+'o'+'p': // nop
if (! *label)
label[0] = '\0';
menu->insert(label);
break;
- case 421: // exec
+ case 'e'+'x'+'e'+'c': // exec
if (! (*label && *command)) {
fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
"BScreen::parseMenuFile: [exec] error, "
break;
- case 442: // exit
+ case 'e'+'x'+'i'+'t': // exit
if (! *label) {
fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
"BScreen::parseMenuFile: [exit] error, "
break;
- case 561: { // style
+ case 's'+'t'+'y'+'l'+'e': { // style
if (! (*label && *command)) {
fprintf(stderr,
i18n(ScreenSet, ScreenSTYLEError,
}
break;
- case 630: // config
+ case 'c'+'o'+'n'+'f'+'i'+'g': // config
if (! *label) {
fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
"BScreen::parseMenufile: [config] error, "
break;
- case 740: { // include
+ case 'i'+'n'+'c'+'l'+'u'+'d'+'e': { // include
if (! *label) {
fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
"BScreen::parseMenuFile: [include] error, "
break;
- case 767: { // submenu
+ case 's'+'u'+'b'+'m'+'e'+'n'+'u': { // submenu
if (! *label) {
fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
"BScreen::parseMenuFile: [submenu] error, "
break;
- case 773: { // restart
+ case 'r'+'e'+'s'+'t'+'a'+'r'+'t': { // restart
if (! *label) {
fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
"BScreen::parseMenuFile: [restart] error, "
break;
- case 845: { // reconfig
+ case 'r'+'e'+'c'+'o'+'n'+'f'+'i'+'g': { // reconfig
if (! *label) {
fprintf(stderr,
i18n(ScreenSet, ScreenRECONFIGError,
break;
- case 995: // stylesdir
- case 1113: { // stylesmenu
+ case 's'+'t'+'y'+'l'+'e'+'s'+'d'+'i'+'r': // stylesdir
+ case 's'+'t'+'y'+'l'+'e'+'s'+'m'+'e'+'n'+'u': { // stylesmenu
bool newmenu = ((key == 1113) ? True : False);
if (! *label || (! *command && newmenu)) {
}
break;
- case 1090: { // workspaces
+ case 'w'+'o'+'r'+'k'+'s'+'p'+'a'+'c'+'e'+'s': { // workspaces
if (! *label) {
fprintf(stderr,
i18n(ScreenSet, ScreenWORKSPACESError,
menu->insert(label, workspacemenu);
}
break;
+
+ case 'p'+'i'+'p'+'e': {
+
+ if (! (*label && *command)) {
+ fprintf(stderr,
+ i18n(ScreenSet, ScreenPIPEError,
+ "BScreen::parseMenuFile: [pipe]"
+ " error, no command defined\n"));
+ continue;
+ }
+ Pipemenu *submenu = new Pipemenu(this, command);
+
+ submenu->setLabel(label);
+
+ submenu->update();
+ menu->insert(label, submenu);
+ rootmenuList.push_back(submenu);
+ break;
+ }
+
}
}
-
+
return ((menu->getCount() == 0) ? True : False);
}
-
void BScreen::shutdown(void) {
XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
XSync(blackbox->getXDisplay(), False);
BScreen(const BScreen&);
BScreen& operator=(const BScreen&);
- bool parseMenuFile(FILE *file, Rootmenu *menu);
-
#ifdef BITMAPBUTTONS
void readDatabaseMask(const std::string &rname,
PixmapMask &pixmapMask,
void showPosition(int x, int y);
void showGeometry(unsigned int gx, unsigned int gy);
void hideGeometry(void);
+ bool parseMenuFile(FILE *file, Rootmenu *menu);
void showWorkspaceMenu(int x, int y);
void showRootMenu(int x, int y);