1 #ifndef WMPROG_H
2 #define WMPROG_H
3 
4 #include "objmenu.h"
5 
6 class ObjectContainer;
7 class YSMListener;
8 class YActionListener;
9 class SwitchWindow;
10 class MenuProgSwitchItems;
11 
12 class MenuLoader {
13 public:
MenuLoader(IApp * app,YSMListener * smActionListener,YActionListener * wmActionListener)14     MenuLoader(IApp *app, YSMListener *smActionListener,
15                YActionListener *wmActionListener) :
16         app(app),
17         smActionListener(smActionListener),
18         wmActionListener(wmActionListener)
19     {
20     }
21 
22     void loadMenus(upath fileName, ObjectContainer *container);
23     void progMenus(const char *command, char *const argv[],
24                    ObjectContainer *container);
25 
26 private:
27     char* parseIncludeStatement(char *p, ObjectContainer *container);
28     char* parseIncludeProgStatement(char *p, ObjectContainer *container);
29     char* parseMenus(char *data, ObjectContainer *container);
30     char* parseAMenu(char *data, ObjectContainer *container);
31     char* parseMenuFile(char *data, ObjectContainer *container);
32     char* parseMenuProg(char *data, ObjectContainer *container);
33     char* parseMenuProgReload(char *data, ObjectContainer *container);
34     char* parseKey(char *word, char *p);
35     char* parseProgram(char *word, char *p, ObjectContainer *container);
36     char* parseWord(char *word, char *p, ObjectContainer *container);
37 
38     IApp *app;
39     YSMListener *smActionListener;
40     YActionListener *wmActionListener;
41 };
42 
43 class DProgram: public DObject {
44     friend class MenuProgSwitchItems;
45 public:
46     virtual ~DProgram();
47 
48     virtual void open();
49 
50     static char *fullname(const char *exe);
51     static DProgram *newProgram(
52         IApp *app,
53         YSMListener *smActionListener,
54         const char *name,
55         ref<YIcon> icon,
56         const bool restart,
57         const char *wmclass,
58         upath exe,
59         YStringArray &args);
60 
61 protected:
62     DProgram(
63         IApp *app,
64         YSMListener *smActionListener,
65         const mstring &name,
66         ref<YIcon> icon,
67         const bool restart,
68         const char *wmclass,
69         upath exe,
70         YStringArray &args);
71 
72 private:
73     const bool fRestart;
74     const char *fRes;
75     long fPid;
76     upath fCmd;
77     YStringArray fArgs;
78     YSMListener *smActionListener;
79 };
80 
81 class DFile: public DObject {
82 public:
83     DFile(IApp *app, const mstring &name, ref<YIcon> icon, upath path);
84     virtual ~DFile();
85 
86     virtual void open();
87 private:
88     upath fPath;
89 };
90 
91 class MenuFileMenu: public ObjectMenu, private MenuLoader {
92 public:
93     MenuFileMenu(
94         IApp *app,
95         YSMListener *smActionListener,
96         YActionListener *wmActionListener,
97         mstring name,
98         YWindow *parent = nullptr);
99     virtual ~MenuFileMenu();
100     virtual void updatePopup();
101     virtual void refresh();
102 private:
103     mstring fName;
104     upath fPath;
105     time_t fModTime;
106 protected:
107     IApp *app;
108 };
109 
110 class MenuProgMenu: public ObjectMenu, private MenuLoader {
111 public:
112     MenuProgMenu(
113         IApp *app,
114         YSMListener *smActionListener,
115         YActionListener *wmActionListener,
116         mstring name,
117         upath command,
118         YStringArray &args,
119         long timeout = 60L,
120         YWindow *parent = nullptr);
121 
122     virtual ~MenuProgMenu();
123     virtual void updatePopup();
124     virtual void refresh();
125 
126 private:
127     mstring fName;
128     upath fCommand;
129     YStringArray fArgs;
130     time_t fModTime;
131     long fTimeout;
132 };
133 
134 class FocusMenu: public YMenu {
135 public:
136     FocusMenu();
137 };
138 
139 class HelpMenu: public ObjectMenu {
140 public:
141     HelpMenu(IApp *app,
142             YSMListener *smActionListener,
143             YActionListener *wmActionListener);
144 };
145 
146 class StartMenu: public MenuFileMenu {
147 public:
148     StartMenu(
149         IApp *app,
150         YSMListener *smActionListener,
151         YActionListener *wmActionListener,
152         const char *name,
153         YWindow *parent = nullptr);
154 
155     virtual bool handleKey(const XKeyEvent &key);
156     virtual void updatePopup();
157     virtual void refresh();
158 
159 private:
160     YSMListener *smActionListener;
161     YActionListener *wmActionListener;
162 };
163 
164 /**
165  * Management item which wraps DProgram and holds the trigger key information.
166  */
167 class KProgram {
168 public:
169     KProgram(const char *key, DProgram *prog, bool bIsDynSwitchMenuProg);
~KProgram()170     ~KProgram() { delete fProg; }
171 
isKey(KeySym key,unsigned int mod)172     bool isKey(KeySym key, unsigned int mod) {
173         return (key == fKey && mod == fMod);
174     }
175     void open(unsigned mods);
key()176     KeySym key() { return fKey; }
modifiers()177     unsigned int modifiers() { return fMod; }
178 
179 private:
180     KeySym fKey;
181     unsigned int fMod;
182     // not a program starter but custom switch menu
183     // use as bool to fit into memory wasted wit 64bit alignment
184     unsigned int bIsDynSwitchMenu;
185     DProgram *fProg;
186     // For dynswitch mode, keep the persistent handler window until its destroyed.
187     // The instance is NOT deleted because there is apparently interference with ywindows cleanup
188     // sequence and this object here is cached over process lifetime anyway.
189     SwitchWindow *pSwitchWindow;
190 };
191 
192 #endif
193 
194 // vim: set sw=4 ts=4 et:
195