From: Scott Moynes Date: Fri, 3 Jan 2003 20:47:09 +0000 (+0000) Subject: Added a [pipe] action to the menu. X-Git-Tag: openbox-2_3_0^2~13 X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=05dc794786cdc8e031231ecebbbcaf6499a65dc5;p=dana%2Fopenbox.git Added a [pipe] action to the menu. 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. --- diff --git a/nls/C/Screen.m b/nls/C/Screen.m index 128c06e7..450c71ef 100644 --- a/nls/C/Screen.m +++ b/nls/C/Screen.m @@ -43,6 +43,8 @@ $ #STYLESDIRErrorNotDir 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 diff --git a/src/Basemenu.cc b/src/Basemenu.cc index 02bd6435..01ca387b 100644 --- a/src/Basemenu.cc +++ b/src/Basemenu.cc @@ -144,7 +144,29 @@ Basemenu::Basemenu(BScreen *scrn) { 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; @@ -164,24 +186,7 @@ Basemenu::~Basemenu(void) { } 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(); } @@ -245,7 +250,6 @@ int Basemenu::remove(int index) { 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()) + @@ -366,6 +370,8 @@ void Basemenu::update(void) { parent->drawSubmenu(parent->which_sub); XMapSubwindows(display, menu.window); + if (visible) + XMapWindow(display, menu.window); } @@ -382,7 +388,6 @@ void Basemenu::show(void) { } } - void Basemenu::hide(void) { if (! torn && hide_tree && parent && parent->isVisible()) { Basemenu *p = parent; @@ -452,7 +457,6 @@ void Basemenu::redrawTitle(void) { style->t_text, text); } - void Basemenu::drawSubmenu(int index) { BasemenuItem *item = find(which_sub); if (item && item->submenu() && ! item->submenu()->isTorn() && @@ -485,7 +489,7 @@ void Basemenu::drawSubmenu(int index) { 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); @@ -502,11 +506,11 @@ void Basemenu::drawSubmenu(int index) { 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; } diff --git a/src/Basemenu.hh b/src/Basemenu.hh index 09c26028..6206b267 100644 --- a/src/Basemenu.hh +++ b/src/Basemenu.hh @@ -46,7 +46,7 @@ private: 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; @@ -65,6 +65,8 @@ private: 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; } @@ -76,11 +78,12 @@ protected: 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; } diff --git a/src/Makefile.am b/src/Makefile.am index 7edd93e7..c8a95d63 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,11 +30,11 @@ CPPFLAGS=@CPPFLAGS@ @DEBUG@ @XFT_CFLAGS@ \ 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 diff --git a/src/Pipemenu.cc b/src/Pipemenu.cc new file mode 100644 index 00000000..eff885f0 --- /dev/null +++ b/src/Pipemenu.cc @@ -0,0 +1,78 @@ +// -*- mode: C++; indent-tabs-mode: nil; -*- +// Pipemenu.cc for Openbox - an X11 Window manager +// Copyright (c) 2002 Scott Moynes +// +// 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 +#endif // HAVE_STDIO_H + +#ifdef HAVE_STDLIB_H +# include +#endif // HAVE_STDLIB_H + +#ifdef HAVE_STRING_H +# include +#endif // HAVE_STRING_H + +#ifdef HAVE_SYS_PARAM_H +# include +#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(); +} diff --git a/src/Pipemenu.hh b/src/Pipemenu.hh new file mode 100644 index 00000000..9a4f7fce --- /dev/null +++ b/src/Pipemenu.hh @@ -0,0 +1,50 @@ +// -*- mode: C++; indent-tabs-mode: nil; -*- +// Pipemenu.hh for Openbox - an X11 Window manager +// Copyright (c) 2002 Scott Moynes +// +// 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 +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 + diff --git a/src/Screen.cc b/src/Screen.cc index ba21224c..c4534904 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -84,6 +84,7 @@ using std::string; #include "Image.hh" #include "Screen.hh" #include "Slit.hh" +#include "Pipemenu.hh" #include "Rootmenu.hh" #include "Toolbar.hh" #include "Util.hh" @@ -2082,7 +2083,7 @@ size_t string_within(char begin, char end, 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); @@ -2092,6 +2093,11 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { if (! fgets(line, 1024, file)) continue; + if (! readData) { + menu->clearMenu(); + readData = True; + } + if (line[0] == '#') // comment, skip it continue; @@ -2118,19 +2124,19 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { 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, " @@ -2142,7 +2148,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { break; - case 442: // exit + case 'e'+'x'+'i'+'t': // exit if (! *label) { fprintf(stderr, i18n(ScreenSet, ScreenEXITError, "BScreen::parseMenuFile: [exit] error, " @@ -2154,7 +2160,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { break; - case 561: { // style + case 's'+'t'+'y'+'l'+'e': { // style if (! (*label && *command)) { fprintf(stderr, i18n(ScreenSet, ScreenSTYLEError, @@ -2169,7 +2175,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { } break; - case 630: // config + case 'c'+'o'+'n'+'f'+'i'+'g': // config if (! *label) { fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError, "BScreen::parseMenufile: [config] error, " @@ -2181,7 +2187,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { break; - case 740: { // include + case 'i'+'n'+'c'+'l'+'u'+'d'+'e': { // include if (! *label) { fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError, "BScreen::parseMenuFile: [include] error, " @@ -2217,7 +2223,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { break; - case 767: { // submenu + case 's'+'u'+'b'+'m'+'e'+'n'+'u': { // submenu if (! *label) { fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError, "BScreen::parseMenuFile: [submenu] error, " @@ -2240,7 +2246,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { break; - case 773: { // restart + case 'r'+'e'+'s'+'t'+'a'+'r'+'t': { // restart if (! *label) { fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError, "BScreen::parseMenuFile: [restart] error, " @@ -2256,7 +2262,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { break; - case 845: { // reconfig + case 'r'+'e'+'c'+'o'+'n'+'f'+'i'+'g': { // reconfig if (! *label) { fprintf(stderr, i18n(ScreenSet, ScreenRECONFIGError, @@ -2270,8 +2276,8 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { 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)) { @@ -2351,7 +2357,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { } break; - case 1090: { // workspaces + case 'w'+'o'+'r'+'k'+'s'+'p'+'a'+'c'+'e'+'s': { // workspaces if (! *label) { fprintf(stderr, i18n(ScreenSet, ScreenWORKSPACESError, @@ -2363,13 +2369,32 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { 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); diff --git a/src/Screen.hh b/src/Screen.hh index b4a64f3b..ca19b2cd 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -197,8 +197,6 @@ private: BScreen(const BScreen&); BScreen& operator=(const BScreen&); - bool parseMenuFile(FILE *file, Rootmenu *menu); - #ifdef BITMAPBUTTONS void readDatabaseMask(const std::string &rname, PixmapMask &pixmapMask, @@ -415,6 +413,7 @@ public: 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);