diff options
Diffstat (limited to 'src/IconbarTool.cc')
-rw-r--r-- | src/IconbarTool.cc | 117 |
1 files changed, 109 insertions, 8 deletions
diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index da9fb59..25b0cf8 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc | |||
@@ -24,6 +24,8 @@ | |||
24 | 24 | ||
25 | #include "IconbarTool.hh" | 25 | #include "IconbarTool.hh" |
26 | 26 | ||
27 | #include "fluxbox.hh" | ||
28 | #include "WindowCmd.hh" | ||
27 | #include "Screen.hh" | 29 | #include "Screen.hh" |
28 | #include "IconbarTheme.hh" | 30 | #include "IconbarTheme.hh" |
29 | #include "Window.hh" | 31 | #include "Window.hh" |
@@ -332,6 +334,92 @@ void removeDuplicate(const IconbarTool::IconList &iconlist, list<FluxboxWindow * | |||
332 | windowlist.erase(remove_it, windowlist.end()); | 334 | windowlist.erase(remove_it, windowlist.end()); |
333 | } | 335 | } |
334 | 336 | ||
337 | typedef FbTk::RefCount<FbTk::Command> RefCmd; | ||
338 | |||
339 | class ShowMenu: public FbTk::Command { | ||
340 | public: | ||
341 | explicit ShowMenu(FluxboxWindow &win):m_win(win) { } | ||
342 | void execute() { | ||
343 | // hide the menu if it's already showing for this FluxboxWindow | ||
344 | if (m_win.menu().isVisible() && WindowCmd<void>::window() == &m_win) { | ||
345 | m_win.screen().hideMenus(); | ||
346 | return; | ||
347 | } | ||
348 | m_win.screen().hideMenus(); | ||
349 | // get last button pos | ||
350 | const XEvent &event = Fluxbox::instance()->lastEvent(); | ||
351 | int x = event.xbutton.x_root - (m_win.menu().width() / 2); | ||
352 | int y = event.xbutton.y_root - (m_win.menu().height() / 2); | ||
353 | m_win.showMenu(x, y); | ||
354 | } | ||
355 | private: | ||
356 | FluxboxWindow &m_win; | ||
357 | }; | ||
358 | |||
359 | class FocusCommand: public FbTk::Command { | ||
360 | public: | ||
361 | explicit FocusCommand(const IconbarTool& tool, FluxboxWindow &win) : | ||
362 | m_win(win), m_tool(tool) { } | ||
363 | void execute() { | ||
364 | // this needs to be a local variable, as this object could be destroyed | ||
365 | // if the workspace is changed. | ||
366 | FluxboxWindow &win = m_win; | ||
367 | if(win.isIconic() || !win.isFocused()) { | ||
368 | switch(win.screen().getUserFollowModel()) { | ||
369 | case BScreen::SEMIFOLLOW_ACTIVE_WINDOW: | ||
370 | if (win.isIconic()) { | ||
371 | win.screen().sendToWorkspace(win.screen().currentWorkspaceID(), &win); | ||
372 | } else { | ||
373 | win.screen().changeWorkspaceID(win.workspaceNumber()); | ||
374 | } | ||
375 | break; | ||
376 | case BScreen::FETCH_ACTIVE_WINDOW: | ||
377 | win.screen().sendToWorkspace(win.screen().currentWorkspaceID(), &win); | ||
378 | break; | ||
379 | case BScreen::FOLLOW_ACTIVE_WINDOW: | ||
380 | if (!win.isStuck()) | ||
381 | win.screen().changeWorkspaceID(win.workspaceNumber()); | ||
382 | default: | ||
383 | break; | ||
384 | }; | ||
385 | win.raiseAndFocus(); | ||
386 | } else | ||
387 | win.iconify(); | ||
388 | } | ||
389 | |||
390 | private: | ||
391 | FluxboxWindow &m_win; | ||
392 | const IconbarTool& m_tool; | ||
393 | }; | ||
394 | |||
395 | // simple forwarding of wheeling, but only | ||
396 | // if desktopwheeling is enabled | ||
397 | class WheelWorkspaceCmd : public FbTk::Command { | ||
398 | public: | ||
399 | explicit WheelWorkspaceCmd(const IconbarTool& tool, FluxboxWindow &win, const char* cmd) : | ||
400 | m_win(win), m_cmd(CommandParser::instance().parseLine(cmd)), m_tool(tool) { } | ||
401 | void execute() { | ||
402 | |||
403 | switch(m_tool.wheelMode()) { | ||
404 | case IconbarTool::ON: | ||
405 | m_cmd->execute(); | ||
406 | break; | ||
407 | case IconbarTool::SCREEN: | ||
408 | if(m_win.screen().isDesktopWheeling()) | ||
409 | m_cmd->execute(); | ||
410 | break; | ||
411 | case IconbarTool::OFF: | ||
412 | default: | ||
413 | break; | ||
414 | }; | ||
415 | } | ||
416 | |||
417 | private: | ||
418 | FluxboxWindow &m_win; | ||
419 | RefCmd m_cmd; | ||
420 | const IconbarTool& m_tool; | ||
421 | }; | ||
422 | |||
335 | }; // end anonymous namespace | 423 | }; // end anonymous namespace |
336 | 424 | ||
337 | IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, BScreen &screen, | 425 | IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, BScreen &screen, |
@@ -779,8 +867,7 @@ void IconbarTool::removeWindow(FluxboxWindow &win) { | |||
779 | win.dieSig().detach(this); | 867 | win.dieSig().detach(this); |
780 | win.workspaceSig().detach(this); | 868 | win.workspaceSig().detach(this); |
781 | win.stateSig().detach(this); | 869 | win.stateSig().detach(this); |
782 | win.titleSig().detach(this); | 870 | win.attentionSig().detach(this); |
783 | |||
784 | 871 | ||
785 | // remove from list and render theme again | 872 | // remove from list and render theme again |
786 | IconButton *button = *it; | 873 | IconButton *button = *it; |
@@ -799,12 +886,26 @@ void IconbarTool::addWindow(FluxboxWindow &win) { | |||
799 | #ifdef DEBUG | 886 | #ifdef DEBUG |
800 | cerr<<"IconbarTool::addWindow(0x"<<&win<<" title = "<<win.title()<<")"<<endl; | 887 | cerr<<"IconbarTool::addWindow(0x"<<&win<<" title = "<<win.title()<<")"<<endl; |
801 | #endif // DEBUG | 888 | #endif // DEBUG |
802 | IconButton *button = new IconButton(*this, | 889 | IconButton *button = new IconButton(m_icon_container, |
803 | m_icon_container, | ||
804 | m_theme.focusedText().font(), | 890 | m_theme.focusedText().font(), |
805 | win); | 891 | win); |
806 | 892 | ||
807 | 893 | ||
894 | RefCmd next_workspace(new ::WheelWorkspaceCmd(*this, win, "nextworkspace")); | ||
895 | RefCmd prev_workspace(new ::WheelWorkspaceCmd(*this, win, "prevworkspace")); | ||
896 | |||
897 | RefCmd focus_cmd(new ::FocusCommand(*this, win)); | ||
898 | RefCmd menu_cmd(new ::ShowMenu(win)); | ||
899 | button->setOnClick(focus_cmd, 1); | ||
900 | button->setOnClick(menu_cmd, 3); | ||
901 | if(win.screen().isReverseWheeling()) { | ||
902 | button->setOnClick(next_workspace, 5); | ||
903 | button->setOnClick(prev_workspace, 4); | ||
904 | } else { | ||
905 | button->setOnClick(next_workspace, 4); | ||
906 | button->setOnClick(prev_workspace, 5); | ||
907 | } | ||
908 | |||
808 | renderButton(*button, false); // update the attributes, but don't clear it | 909 | renderButton(*button, false); // update the attributes, but don't clear it |
809 | m_icon_container.insertItem(button); | 910 | m_icon_container.insertItem(button); |
810 | m_icon_list.push_back(button); | 911 | m_icon_list.push_back(button); |
@@ -818,10 +919,10 @@ void IconbarTool::addWindow(FluxboxWindow &win) { | |||
818 | } | 919 | } |
819 | 920 | ||
820 | void IconbarTool::updateList() { | 921 | void IconbarTool::updateList() { |
821 | list<WinClient *> ordered_list = | 922 | list<Focusable *> ordered_list = |
822 | m_screen.focusControl().creationOrderList(); | 923 | m_screen.focusControl().creationOrderWinList(); |
823 | list<WinClient *>::iterator it = ordered_list.begin(); | 924 | list<Focusable *>::iterator it = ordered_list.begin(); |
824 | list<WinClient *>::iterator it_end = ordered_list.end(); | 925 | list<Focusable *>::iterator it_end = ordered_list.end(); |
825 | for (; it != it_end; ++it) { | 926 | for (; it != it_end; ++it) { |
826 | if ((*it)->fbwindow() && checkAddWindow(mode(), *(*it)->fbwindow()) && | 927 | if ((*it)->fbwindow() && checkAddWindow(mode(), *(*it)->fbwindow()) && |
827 | !checkDuplicate(*(*it)->fbwindow())) | 928 | !checkDuplicate(*(*it)->fbwindow())) |