diff options
author | Mathias Gumz <akira@fluxbox.org> | 2015-01-15 17:49:35 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2015-01-15 17:49:45 (GMT) |
commit | bd9afcafb93382b5b7f32c222594699214581596 (patch) | |
tree | 418583c08c6e5ebdfcd172f5aba96d465c27d47b /src/ConfigMenu.cc | |
parent | 8387742c8860694777f7c2c62da0a90c9e836988 (diff) | |
download | fluxbox-bd9afcafb93382b5b7f32c222594699214581596.zip fluxbox-bd9afcafb93382b5b7f32c222594699214581596.tar.bz2 |
Refactor: split out menu generation from BScreen
Again, it's easier to read the code when the whole menu-generation is out of
the way.
Diffstat (limited to 'src/ConfigMenu.cc')
-rw-r--r-- | src/ConfigMenu.cc | 333 |
1 files changed, 333 insertions, 0 deletions
diff --git a/src/ConfigMenu.cc b/src/ConfigMenu.cc new file mode 100644 index 0000000..e4be129 --- /dev/null +++ b/src/ConfigMenu.cc | |||
@@ -0,0 +1,333 @@ | |||
1 | // ConfigMenu.cc for Fluxbox Window Manager | ||
2 | // Copyright (c) 2015 - Mathias Gumz <akira@fluxbox.org> | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | #include "ConfigMenu.hh" | ||
23 | #include "Screen.hh" | ||
24 | #include "fluxbox.hh" | ||
25 | |||
26 | #include "FocusModelMenuItem.hh" | ||
27 | #include "ScreenPlacement.hh" | ||
28 | #include "FbMenu.hh" | ||
29 | #include "FbTk/Menu.hh" | ||
30 | #include "FbTk/BoolMenuItem.hh" | ||
31 | #include "FbTk/IntMenuItem.hh" | ||
32 | #include "FbTk/MenuSeparator.hh" | ||
33 | #include "FbTk/RadioMenuItem.hh" | ||
34 | |||
35 | #include "FbTk/MacroCommand.hh" | ||
36 | #include "FbTk/CommandParser.hh" | ||
37 | #include "FbTk/SimpleCommand.hh" | ||
38 | |||
39 | #include "FbTk/Transparent.hh" | ||
40 | #include "FbTk/Resource.hh" | ||
41 | #include "FbTk/I18n.hh" | ||
42 | |||
43 | namespace { | ||
44 | |||
45 | class TabPlacementMenuItem: public FbTk::RadioMenuItem { | ||
46 | public: | ||
47 | TabPlacementMenuItem(const FbTk::FbString & label, BScreen &screen, | ||
48 | FbWinFrame::TabPlacement place, | ||
49 | FbTk::RefCount<FbTk::Command<void> > &cmd): | ||
50 | FbTk::RadioMenuItem(label, cmd), | ||
51 | m_screen(screen), | ||
52 | m_place(place) { | ||
53 | setCloseOnClick(false); | ||
54 | } | ||
55 | |||
56 | bool isSelected() const { return m_screen.getTabPlacement() == m_place; } | ||
57 | void click(int button, int time, unsigned int mods) { | ||
58 | m_screen.saveTabPlacement(m_place); | ||
59 | FbTk::RadioMenuItem::click(button, time, mods); | ||
60 | } | ||
61 | |||
62 | private: | ||
63 | BScreen &m_screen; | ||
64 | FbWinFrame::TabPlacement m_place; | ||
65 | }; | ||
66 | |||
67 | |||
68 | typedef FbTk::RefCount<FbTk::Command<void> > _Cmd; | ||
69 | |||
70 | enum { | ||
71 | L_ALPHA = 0, | ||
72 | L_PSEUDO_TRANS, | ||
73 | L_FOCUS_ALPHA, | ||
74 | L_UNFOCUS_ALPHA, | ||
75 | L_MENU_ALPHA, | ||
76 | }; | ||
77 | |||
78 | |||
79 | void setupAlphaMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_reconf) { | ||
80 | #ifdef HAVE_XRENDER | ||
81 | _FB_USES_NLS; | ||
82 | |||
83 | static const FbTk::FbString _labels[] = { | ||
84 | _FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"), | ||
85 | _FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), | ||
86 | _FB_XTEXT(Configmenu, FocusedAlpha, "Focused Window Alpha", "Transparency level of the focused window"), | ||
87 | _FB_XTEXT(Configmenu, UnfocusedAlpha, "Unfocused Window Alpha", "Transparency level of unfocused windows"), | ||
88 | _FB_XTEXT(Configmenu, MenuAlpha, "Menu Alpha", "Transparency level of menu") | ||
89 | }; | ||
90 | |||
91 | |||
92 | FbTk::FbString label = _labels[L_ALPHA]; | ||
93 | FbTk::Menu* menu = sh.screen.createMenu(label); | ||
94 | |||
95 | if (FbTk::Transparent::haveComposite(true)) { | ||
96 | static FbTk::SimpleAccessor<bool> s_pseudo = Fluxbox::instance()->getPseudoTrans(); | ||
97 | menu->insertItem(new FbTk::BoolMenuItem(_labels[L_PSEUDO_TRANS], s_pseudo, save_reconf)); | ||
98 | } | ||
99 | |||
100 | // in order to save system resources, don't save or reconfigure alpha | ||
101 | // settings until after the user is done changing them | ||
102 | _Cmd delayed_save_and_reconf(new FbTk::DelayedCmd(save_reconf)); | ||
103 | |||
104 | FbTk::MenuItem *focused_alpha_item = | ||
105 | new FbTk::IntMenuItem(_labels[L_FOCUS_ALPHA], sh.resource.focused_alpha, 0, 255, *menu); | ||
106 | focused_alpha_item->setCommand(delayed_save_and_reconf); | ||
107 | menu->insertItem(focused_alpha_item); | ||
108 | |||
109 | FbTk::MenuItem *unfocused_alpha_item = | ||
110 | new FbTk::IntMenuItem(_labels[L_UNFOCUS_ALPHA], sh.resource.unfocused_alpha, 0, 255, *menu); | ||
111 | unfocused_alpha_item->setCommand(delayed_save_and_reconf); | ||
112 | menu->insertItem(unfocused_alpha_item); | ||
113 | |||
114 | FbTk::MenuItem *menu_alpha_item = | ||
115 | new FbTk::IntMenuItem(_labels[L_MENU_ALPHA], sh.resource.menu_alpha, 0, 255, *menu); | ||
116 | menu_alpha_item->setCommand(delayed_save_and_reconf); | ||
117 | menu->insertItem(menu_alpha_item); | ||
118 | |||
119 | menu->updateMenu(); | ||
120 | parent.insertSubmenu(label, menu); | ||
121 | #endif | ||
122 | } | ||
123 | |||
124 | |||
125 | #define _BOOLITEM(m,a, b, c, d, e, f) (m).insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f)) | ||
126 | |||
127 | void setupFocusMenu(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh, _Cmd& save_rc, _Cmd& save_reconf) { | ||
128 | |||
129 | _FB_USES_NLS; | ||
130 | |||
131 | // we don't set this to internal menu so will | ||
132 | // be deleted toghether with the parent | ||
133 | FbTk::FbString label = _FB_XTEXT(Configmenu, FocusModel, "Focus Model", "Method used to give focus to windows"); | ||
134 | FbMenu* fm = sh.screen.createMenu(label); | ||
135 | |||
136 | #define _FOCUSITEM(a, b, c, d, e) \ | ||
137 | fm->insertItem(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), sh.screen.focusControl(), \ | ||
138 | e, save_reconf)) | ||
139 | |||
140 | _FOCUSITEM(Configmenu, ClickFocus, | ||
141 | "Click To Focus", "Click to focus", | ||
142 | FocusControl::CLICKFOCUS); | ||
143 | _FOCUSITEM(Configmenu, MouseFocus, | ||
144 | "Mouse Focus (Keyboard Friendly)", | ||
145 | "Mouse Focus (Keyboard Friendly)", | ||
146 | FocusControl::MOUSEFOCUS); | ||
147 | _FOCUSITEM(Configmenu, StrictMouseFocus, | ||
148 | "Mouse Focus (Strict)", | ||
149 | "Mouse Focus (Strict)", | ||
150 | FocusControl::STRICTMOUSEFOCUS); | ||
151 | #undef _FOCUSITEM | ||
152 | |||
153 | fm->insertItem(new FbTk::MenuSeparator()); | ||
154 | fm->insertItem(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, | ||
155 | ClickTabFocus, "ClickTabFocus", "Click tab to focus windows"), | ||
156 | sh.screen.focusControl(), FocusControl::CLICKTABFOCUS, save_reconf)); | ||
157 | fm->insertItem(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, | ||
158 | MouseTabFocus, "MouseTabFocus", "Hover over tab to focus windows"), | ||
159 | sh.screen.focusControl(), FocusControl::MOUSETABFOCUS, save_reconf)); | ||
160 | fm->insertItem(new FbTk::MenuSeparator()); | ||
161 | |||
162 | try { | ||
163 | fm->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, | ||
164 | "Focus New Windows", "Focus newly created windows"), | ||
165 | sh.rm.getResource<bool>(sh.screen.name() + ".focusNewWindows"), | ||
166 | save_rc)); | ||
167 | } catch (FbTk::ResourceException & e) { | ||
168 | std::cerr<<e.what()<<std::endl; | ||
169 | } | ||
170 | |||
171 | #ifdef XINERAMA | ||
172 | try { | ||
173 | fm->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusSameHead, | ||
174 | "Keep Head", "Only revert focus on same head"), | ||
175 | sh.rm.getResource<bool>(sh.screen.name() + ".focusSameHead"), | ||
176 | save_rc)); | ||
177 | } catch (FbTk::ResourceException e) { | ||
178 | std::cerr << e.what() << std::endl; | ||
179 | } | ||
180 | #endif // XINERAMA | ||
181 | |||
182 | _BOOLITEM(*fm, Configmenu, AutoRaise, | ||
183 | "Auto Raise", "Auto Raise windows on sloppy", | ||
184 | sh.resource.auto_raise, save_rc); | ||
185 | _BOOLITEM(*fm, Configmenu, ClickRaises, | ||
186 | "Click Raises", "Click Raises", | ||
187 | sh.resource.click_raises, save_rc); | ||
188 | |||
189 | fm->updateMenu(); | ||
190 | menu.insertSubmenu(label, fm); | ||
191 | } | ||
192 | |||
193 | |||
194 | void setupMaximizeMenu(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh, _Cmd& save_rc) { | ||
195 | |||
196 | _FB_USES_NLS; | ||
197 | |||
198 | FbTk::FbString label = _FB_XTEXT(Configmenu, MaxMenu, | ||
199 | "Maximize Options", "heading for maximization options"); | ||
200 | FbTk::Menu* mm = sh.screen.createMenu(label); | ||
201 | |||
202 | _BOOLITEM(*mm, Configmenu, FullMax, | ||
203 | "Full Maximization", "Maximise over slit, toolbar, etc", | ||
204 | sh.resource.full_max, save_rc); | ||
205 | _BOOLITEM(*mm, Configmenu, MaxIgnoreInc, | ||
206 | "Ignore Resize Increment", | ||
207 | "Maximizing Ignores Resize Increment (e.g. xterm)", | ||
208 | sh.resource.max_ignore_inc, save_rc); | ||
209 | _BOOLITEM(*mm, Configmenu, MaxDisableMove, | ||
210 | "Disable Moving", "Don't Allow Moving While Maximized", | ||
211 | sh.resource.max_disable_move, save_rc); | ||
212 | _BOOLITEM(*mm, Configmenu, MaxDisableResize, | ||
213 | "Disable Resizing", "Don't Allow Resizing While Maximized", | ||
214 | sh.resource.max_disable_resize, save_rc); | ||
215 | |||
216 | mm->updateMenu(); | ||
217 | menu.insertSubmenu(label, mm); | ||
218 | } | ||
219 | |||
220 | void setupTabMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_reconf, _Cmd& save_reconftabs) { | ||
221 | |||
222 | _FB_USES_NLS; | ||
223 | |||
224 | FbTk::FbString label = _FB_XTEXT(Configmenu, TabMenu, "Tab Options", "heading for tab-related options"); | ||
225 | // TODO: main-category is 'Menu'?? should be 'ConfigMenu'??? | ||
226 | FbTk::FbString p_label = _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"); | ||
227 | FbTk::Menu* menu = sh.screen.createMenu(label); | ||
228 | FbTk::Menu* p_menu = sh.screen.createToggleMenu(p_label); | ||
229 | |||
230 | menu->insertSubmenu(p_label, p_menu); | ||
231 | |||
232 | menu->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, TabsInTitlebar, | ||
233 | "Tabs in Titlebar", "Tabs in Titlebar"), | ||
234 | sh.resource.default_internal_tabs, save_reconftabs)); | ||
235 | menu->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, | ||
236 | "Maximize Over", "Maximize over this thing when maximizing"), | ||
237 | sh.resource.max_over_tabs, save_reconf)); | ||
238 | menu->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, | ||
239 | "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), | ||
240 | sh.resource.tabs_use_pixmap, save_reconf)); | ||
241 | |||
242 | FbTk::MenuItem *tab_width_item = | ||
243 | new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, ExternalTabWidth, | ||
244 | "External Tab Width", | ||
245 | "Width of external-style tabs"), | ||
246 | sh.resource.tab_width, 10, 3000, /* silly number */ | ||
247 | *menu); | ||
248 | tab_width_item->setCommand(save_reconftabs); | ||
249 | menu->insertItem(tab_width_item); | ||
250 | |||
251 | // menu is 3 wide, 5 down | ||
252 | struct PlacementP { | ||
253 | const FbTk::FbString label; | ||
254 | FbWinFrame::TabPlacement placement; | ||
255 | }; | ||
256 | static const PlacementP place_menu[] = { | ||
257 | |||
258 | { _FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), FbWinFrame::TOPLEFT}, | ||
259 | { _FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), FbWinFrame::LEFTTOP}, | ||
260 | { _FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), FbWinFrame::LEFT}, | ||
261 | { _FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), FbWinFrame::LEFTBOTTOM}, | ||
262 | { _FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), FbWinFrame::BOTTOMLEFT}, | ||
263 | { _FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), FbWinFrame::TOP}, | ||
264 | { "", FbWinFrame::TOPLEFT}, | ||
265 | { "", FbWinFrame::TOPLEFT}, | ||
266 | { "", FbWinFrame::TOPLEFT}, | ||
267 | { _FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), FbWinFrame::BOTTOM}, | ||
268 | { _FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), FbWinFrame::TOPRIGHT}, | ||
269 | { _FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), FbWinFrame::RIGHTTOP}, | ||
270 | { _FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), FbWinFrame::RIGHT}, | ||
271 | { _FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), FbWinFrame::RIGHTBOTTOM}, | ||
272 | { _FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), FbWinFrame::BOTTOMRIGHT} | ||
273 | }; | ||
274 | |||
275 | p_menu->setMinimumColumns(3); | ||
276 | // create items in sub menu | ||
277 | for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { | ||
278 | const PlacementP& p = place_menu[i]; | ||
279 | if (p.label == "") { | ||
280 | p_menu->insert(p.label); | ||
281 | p_menu->setItemEnabled(i, false); | ||
282 | } else | ||
283 | p_menu->insertItem(new TabPlacementMenuItem(p.label, | ||
284 | sh.screen, p.placement, save_reconftabs)); | ||
285 | } | ||
286 | p_menu->updateMenu(); | ||
287 | parent.insertSubmenu(label, menu); | ||
288 | } | ||
289 | |||
290 | } | ||
291 | |||
292 | |||
293 | void ConfigMenu::setup(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh) { | ||
294 | |||
295 | _FB_USES_NLS; | ||
296 | |||
297 | FbTk::MacroCommand *s_a_reconf_macro = new FbTk::MacroCommand(); | ||
298 | FbTk::MacroCommand *s_a_reconftabs_macro = new FbTk::MacroCommand(); | ||
299 | _Cmd saverc_cmd(new FbTk::SimpleCommand<Fluxbox>( *Fluxbox::instance(), &Fluxbox::save_rc)); | ||
300 | _Cmd reconf_cmd(FbTk::CommandParser<void>::instance().parse("reconfigure")); | ||
301 | _Cmd reconftabs_cmd(new FbTk::SimpleCommand<BScreen>(sh.screen, &BScreen::reconfigureTabs)); | ||
302 | s_a_reconf_macro->add(saverc_cmd); | ||
303 | s_a_reconf_macro->add(reconf_cmd); | ||
304 | s_a_reconftabs_macro->add(saverc_cmd); | ||
305 | s_a_reconftabs_macro->add(reconftabs_cmd); | ||
306 | |||
307 | _Cmd save_and_reconfigure(s_a_reconf_macro); | ||
308 | _Cmd save_and_reconftabs(s_a_reconftabs_macro); | ||
309 | |||
310 | setupFocusMenu(menu, sh, saverc_cmd, save_and_reconfigure); | ||
311 | setupMaximizeMenu(menu, sh, saverc_cmd); | ||
312 | setupTabMenu(menu, sh, save_and_reconfigure, save_and_reconftabs); | ||
313 | |||
314 | #ifdef HAVE_XRENDER | ||
315 | if (FbTk::Transparent::haveRender() || | ||
316 | FbTk::Transparent::haveComposite()) { | ||
317 | setupAlphaMenu(menu, sh, save_and_reconfigure); | ||
318 | } | ||
319 | #endif // HAVE_XRENDER | ||
320 | |||
321 | _BOOLITEM(menu, Configmenu, OpaqueMove, | ||
322 | "Opaque Window Moving", | ||
323 | "Window Moving with whole window visible (as opposed to outline moving)", | ||
324 | sh.resource.opaque_move, saverc_cmd); | ||
325 | _BOOLITEM(menu, Configmenu, WorkspaceWarping, | ||
326 | "Workspace Warping", | ||
327 | "Workspace Warping - dragging windows to the edge and onto the next workspace", | ||
328 | sh.resource.workspace_warping, saverc_cmd); | ||
329 | |||
330 | #undef _BOOLITEM | ||
331 | |||
332 | menu.updateMenu(); | ||
333 | } | ||