aboutsummaryrefslogtreecommitdiff
path: root/src/IconButton.cc
diff options
context:
space:
mode:
authormarkt <markt>2007-03-24 16:31:13 (GMT)
committermarkt <markt>2007-03-24 16:31:13 (GMT)
commit1829dd5780c9cd818884cb84ae1ea51a4d4d35ca (patch)
treeaffbf9ced07d3c52c04dd49a81e14be117326360 /src/IconButton.cc
parent5c811e63012f160b5e60a38deca10d01b5d23e69 (diff)
downloadfluxbox-1829dd5780c9cd818884cb84ae1ea51a4d4d35ca.zip
fluxbox-1829dd5780c9cd818884cb84ae1ea51a4d4d35ca.tar.bz2
colossal multi-patch, encompassing all of what I did yesterday without internet access
Diffstat (limited to 'src/IconButton.cc')
-rw-r--r--src/IconButton.cc131
1 files changed, 5 insertions, 126 deletions
diff --git a/src/IconButton.cc b/src/IconButton.cc
index 545ee1d..8530c83 100644
--- a/src/IconButton.cc
+++ b/src/IconButton.cc
@@ -25,12 +25,8 @@
25#include "IconButton.hh" 25#include "IconButton.hh"
26#include "IconbarTool.hh" 26#include "IconbarTool.hh"
27 27
28#include "fluxbox.hh"
29#include "Screen.hh" 28#include "Screen.hh"
30#include "Window.hh" 29#include "Focusable.hh"
31#include "WinClient.hh"
32#include "CommandParser.hh"
33#include "WindowCmd.hh"
34 30
35#include "FbTk/App.hh" 31#include "FbTk/App.hh"
36#include "FbTk/SimpleCommand.hh" 32#include "FbTk/SimpleCommand.hh"
@@ -49,123 +45,15 @@
49#include <X11/extensions/shape.h> 45#include <X11/extensions/shape.h>
50#endif // SHAPE 46#endif // SHAPE
51 47
52typedef FbTk::RefCount<FbTk::Command> RefCmd;
53
54namespace {
55
56class ShowMenu: public FbTk::Command {
57public:
58 explicit ShowMenu(FluxboxWindow &win):m_win(win) { }
59 void execute() {
60 // hide the menu if it's already showing for this FluxboxWindow
61 if (m_win.menu().isVisible() && WindowCmd<void>::window() == &m_win) {
62 m_win.screen().hideMenus();
63 return;
64 }
65 m_win.screen().hideMenus();
66 // get last button pos
67 const XEvent &event = Fluxbox::instance()->lastEvent();
68 int x = event.xbutton.x_root - (m_win.menu().width() / 2);
69 int y = event.xbutton.y_root - (m_win.menu().height() / 2);
70 m_win.showMenu(x, y);
71 }
72private:
73 FluxboxWindow &m_win;
74};
75
76class FocusCommand: public FbTk::Command {
77public:
78 explicit FocusCommand(const IconbarTool& tool, FluxboxWindow &win) :
79 m_win(win), m_tool(tool) { }
80 void execute() {
81 // this needs to be a local variable, as this object could be destroyed
82 // if the workspace is changed.
83 FluxboxWindow &win = m_win;
84 if(win.isIconic() || !win.isFocused()) {
85 switch(win.screen().getUserFollowModel()) {
86 case BScreen::SEMIFOLLOW_ACTIVE_WINDOW:
87 if (win.isIconic()) {
88 win.screen().sendToWorkspace(win.screen().currentWorkspaceID(), &win);
89 } else {
90 win.screen().changeWorkspaceID(win.workspaceNumber());
91 }
92 break;
93 case BScreen::FETCH_ACTIVE_WINDOW:
94 win.screen().sendToWorkspace(win.screen().currentWorkspaceID(), &win);
95 break;
96 case BScreen::FOLLOW_ACTIVE_WINDOW:
97 if (!win.isStuck())
98 win.screen().changeWorkspaceID(win.workspaceNumber());
99 default:
100 break;
101 };
102 win.raiseAndFocus();
103 } else
104 win.iconify();
105 }
106
107private:
108 FluxboxWindow &m_win;
109 const IconbarTool& m_tool;
110};
111
112// simple forwarding of wheeling, but only
113// if desktopwheeling is enabled
114class WheelWorkspaceCmd : public FbTk::Command {
115public:
116 explicit WheelWorkspaceCmd(const IconbarTool& tool, FluxboxWindow &win, const char* cmd) :
117 m_win(win), m_cmd(CommandParser::instance().parseLine(cmd)), m_tool(tool) { }
118 void execute() {
119
120 switch(m_tool.wheelMode()) {
121 case IconbarTool::ON:
122 m_cmd->execute();
123 break;
124 case IconbarTool::SCREEN:
125 if(m_win.screen().isDesktopWheeling())
126 m_cmd->execute();
127 break;
128 case IconbarTool::OFF:
129 default:
130 break;
131 };
132 }
133
134private:
135 FluxboxWindow &m_win;
136 RefCmd m_cmd;
137 const IconbarTool& m_tool;
138};
139 48
140} // end anonymous namespace 49IconButton::IconButton(const FbTk::FbWindow &parent, FbTk::Font &font,
141 50 Focusable &win):
142 51 FbTk::TextButton(parent, font, win.title()),
143
144IconButton::IconButton(const IconbarTool& tool, const FbTk::FbWindow &parent,
145 FbTk::Font &font, FluxboxWindow &win):
146 FbTk::TextButton(parent, font, win.winClient().title()),
147 m_win(win), 52 m_win(win),
148 m_icon_window(*this, 1, 1, 1, 1, 53 m_icon_window(*this, 1, 1, 1, 1,
149 ExposureMask | ButtonPressMask | ButtonReleaseMask), 54 ExposureMask | ButtonPressMask | ButtonReleaseMask),
150 m_use_pixmap(true) { 55 m_use_pixmap(true) {
151 56
152
153 RefCmd next_workspace(new ::WheelWorkspaceCmd(tool, m_win, "nextworkspace"));
154 RefCmd prev_workspace(new ::WheelWorkspaceCmd(tool, m_win, "prevworkspace"));
155
156 RefCmd focus_cmd(new ::FocusCommand(tool, m_win));
157 RefCmd menu_cmd(new ::ShowMenu(m_win));
158 setOnClick(focus_cmd, 1);
159 setOnClick(menu_cmd, 3);
160 if(win.screen().isReverseWheeling()) {
161 setOnClick(next_workspace, 5);
162 setOnClick(prev_workspace, 4);
163 } else {
164 setOnClick(next_workspace, 4);
165 setOnClick(prev_workspace, 5);
166 }
167
168 m_win.hintSig().attach(this);
169 m_win.titleSig().attach(this); 57 m_win.titleSig().attach(this);
170 58
171 FbTk::EventManager::instance()->add(*this, m_icon_window); 59 FbTk::EventManager::instance()->add(*this, m_icon_window);
@@ -227,10 +115,6 @@ void IconButton::update(FbTk::Subject *subj) {
227 // icon pixmap was updated, 115 // icon pixmap was updated,
228 // so we refresh everything 116 // so we refresh everything
229 117
230 // we need to check our client first
231 if (m_win.clientList().empty())
232 return;
233
234 Display *display = FbTk::App::instance()->display(); 118 Display *display = FbTk::App::instance()->display();
235 119
236 int screen = m_win.screen().screenNumber(); 120 int screen = m_win.screen().screenNumber();
@@ -298,13 +182,8 @@ void IconButton::update(FbTk::Subject *subj) {
298} 182}
299 183
300void IconButton::setupWindow() { 184void IconButton::setupWindow() {
301
302 m_icon_window.clear(); 185 m_icon_window.clear();
303 186 setText(m_win.title());
304 if (!m_win.clientList().empty()) {
305 setText(m_win.winClient().title());
306 // draw with x offset and y offset
307 }
308 FbTk::TextButton::clear(); 187 FbTk::TextButton::clear();
309} 188}
310 189