wmi

git clone git://oldgit.suckless.org/wmi/
Log | Files | Refs | LICENSE

menu.h (1906B)


      1 // Copyright (c) 2003 - 2009 Anselm R Garbe <anselm@garbe.us>
      2 // See LICENSE for license details.
      3 
      4 #ifndef __MENU_H
      5 #define __MENU_H
      6 
      7 #include "wmi.h"
      8 
      9 extern "C" {
     10 #include <X11/Xlib.h>
     11 }
     12 
     13 #include <list>
     14 #include <string>
     15 
     16 #include "widget.h"
     17 
     18 class Action;
     19 class Client;
     20 class Item;
     21 class Label;
     22 class Monitor;
     23 class Theme;
     24 
     25 typedef list<Action *> LAction;
     26 typedef list<Item *> LItem;
     27 
     28 /**
     29  * Items for menu.
     30  */
     31 class Item {
     32 
     33 public:
     34 
     35     // The type of this items is related to the data_ pointer which must
     36     // of following type if the specific type has been choosen:
     37     //   ACTION -> Action *
     38     //   CLIENT -> Client * (attached client)
     39     //   DCLIENT -> Client * (detached client)
     40     //   WORKSPACE -> Workspace *
     41     //   ROOT -> 0
     42     //   ROOTITEM -> 0
     43     //   SEPARATOR -> 0
     44     enum Type {ACTION, CLIENT, DCLIENT, WORKSPACE, ROOT,
     45                ROOTITEM, SEPARATOR};
     46 
     47     Item(string name, void *data, Type type);
     48     ~Item();
     49 
     50     LItem *items();
     51 
     52     void addItem(Item *item);
     53     void removeItem(Item *item);
     54 
     55     Type type() const;
     56     string name() const;
     57     Item *parent() const;
     58     void setParent(Item *parent);
     59     void *data() const;
     60 
     61     unsigned int size();
     62 
     63 private:
     64 
     65     string name_;
     66     void *data_;
     67     LItem items_;
     68     Type type_;
     69     Item *parent_;
     70 
     71 };
     72 
     73 
     74 /**
     75  * Basic menu for action, cut'n'paste and re-attach stuff.
     76  */
     77 class Menu : public Widget {
     78 
     79 public:
     80 
     81     Menu(Monitor *monitor);
     82 
     83     ~Menu();
     84 
     85     void manage();
     86     void updateItemTree();
     87 
     88     /** called on Expose by Kernel. */
     89     void illuminate();
     90 
     91     void handleButtonPress(XButtonEvent *event);
     92     void handleMotionNotify(XMotionEvent *event);
     93 
     94     virtual void show();
     95     virtual void hide();
     96 
     97 private:
     98 
     99     void initActions();
    100 
    101     void escape();
    102 
    103     Theme *theme_;
    104     Label *label_;
    105     LAction actions_;
    106     Item *root_;
    107     Item *subRoot_;
    108     Item *selected_;
    109 };
    110 
    111 #endif // __MENU_H