]> Dogcows Code - chaz/openbox/blob - src/Windowmenu.cc
sync with bb-cvs
[chaz/openbox] / src / Windowmenu.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // Windowmenu.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifdef HAVE_CONFIG_H
25 # include "../config.h"
26 #endif // HAVE_CONFIG_H
27
28 extern "C" {
29 #ifdef HAVE_STRING_H
30 # include <string.h>
31 #endif // HAVE_STRING_H
32 }
33
34 #include "i18n.hh"
35 #include "blackbox.hh"
36 #include "Screen.hh"
37 #include "Window.hh"
38 #include "Windowmenu.hh"
39 #include "Workspace.hh"
40
41
42 Windowmenu::Windowmenu(BlackboxWindow *win) : Basemenu(win->getScreen()) {
43 window = win;
44
45 setTitleVisibility(False);
46 setMovable(False);
47 setInternalMenu();
48
49 sendToMenu = new SendtoWorkspacemenu(this);
50 insert(i18n(WindowmenuSet, WindowmenuSendTo, "Send To ..."),
51 sendToMenu);
52 insert(i18n(WindowmenuSet, WindowmenuShade, "Shade"),
53 BScreen::WindowShade);
54 insert(i18n(WindowmenuSet, WindowmenuIconify, "Iconify"),
55 BScreen::WindowIconify);
56 insert(i18n(WindowmenuSet, WindowmenuMaximize, "Maximize"),
57 BScreen::WindowMaximize);
58 insert(i18n(WindowmenuSet, WindowmenuRaise,"Raise"),
59 BScreen::WindowRaise);
60 insert(i18n(WindowmenuSet, WindowmenuLower, "Lower"),
61 BScreen::WindowLower);
62 insert(i18n(WindowmenuSet, WindowmenuStick, "Stick"),
63 BScreen::WindowStick);
64 insert(i18n(WindowmenuSet, WindowmenuKillClient, "Kill Client"),
65 BScreen::WindowKill);
66 insert(i18n(WindowmenuSet, WindowmenuClose, "Close"),
67 BScreen::WindowClose);
68
69 update();
70
71 setItemEnabled(1, window->hasTitlebar());
72 setItemEnabled(2, window->isIconifiable());
73 setItemEnabled(3, window->isMaximizable());
74 setItemEnabled(8, window->isClosable());
75 }
76
77
78 Windowmenu::~Windowmenu(void) {
79 delete sendToMenu;
80 }
81
82
83 void Windowmenu::show(void) {
84 if (isItemEnabled(1)) setItemSelected(1, window->isShaded());
85 if (isItemEnabled(3)) setItemSelected(3, window->isMaximized());
86 if (isItemEnabled(6)) setItemSelected(6, window->isStuck());
87
88 Basemenu::show();
89 }
90
91
92 void Windowmenu::itemSelected(int button, unsigned int index) {
93 if (button != 1)
94 return;
95
96 BasemenuItem *item = find(index);
97
98 hide();
99 switch (item->function()) {
100 case BScreen::WindowShade:
101 window->shade();
102 break;
103
104 case BScreen::WindowIconify:
105 window->iconify();
106 break;
107
108 case BScreen::WindowMaximize:
109 window->maximize(1); // full maximize
110 break;
111
112 case BScreen::WindowClose:
113 window->close();
114 break;
115
116 case BScreen::WindowRaise: {
117 Workspace *wkspc =
118 getScreen()->getWorkspace(window->getWorkspaceNumber());
119 wkspc->raiseWindow(window);
120 }
121 break;
122
123 case BScreen::WindowLower: {
124 Workspace *wkspc =
125 getScreen()->getWorkspace(window->getWorkspaceNumber());
126 wkspc->lowerWindow(window);
127 }
128 break;
129
130 case BScreen::WindowStick:
131 window->stick();
132 break;
133
134 case BScreen::WindowKill:
135 XKillClient(getScreen()->getBaseDisplay()->getXDisplay(),
136 window->getClientWindow());
137 break;
138 }
139 }
140
141
142 void Windowmenu::reconfigure(void) {
143 setItemEnabled(1, window->hasTitlebar());
144 setItemEnabled(2, window->isIconifiable());
145 setItemEnabled(3, window->isMaximizable());
146 setItemEnabled(8, window->isClosable());
147
148 sendToMenu->reconfigure();
149
150 Basemenu::reconfigure();
151 }
152
153
154 Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu *w)
155 : Basemenu(w->getScreen()) {
156
157 window = w->window;
158
159 setTitleVisibility(False);
160 setMovable(False);
161 setInternalMenu();
162 update();
163 }
164
165
166 void Windowmenu::SendtoWorkspacemenu::itemSelected(int button,
167 unsigned int index) {
168 if (button > 2) return;
169
170 if (index <= getScreen()->getWorkspaceCount()) {
171 if (index == getScreen()->getCurrentWorkspaceID()) return;
172 if (window->isStuck()) window->stick();
173
174 if (button == 1) window->withdraw();
175 getScreen()->reassociateWindow(window, index, True);
176 if (button == 2) getScreen()->changeWorkspaceID(index);
177 }
178 hide();
179 }
180
181
182 void Windowmenu::SendtoWorkspacemenu::update(void) {
183 unsigned int i, r = getCount(),
184 workspace_count = getScreen()->getWorkspaceCount();
185 if (r > workspace_count) {
186 for (i = r; i < workspace_count; ++i)
187 remove(0);
188 r = getCount();
189 }
190
191 for (i = 0; i < workspace_count; ++i) {
192 if (r < workspace_count) {
193 insert(getScreen()->getWorkspace(i)->getName());
194 ++r;
195 } else {
196 changeItemLabel(i, getScreen()->getWorkspace(i)->getName());
197 setItemEnabled(i, i != getScreen()->getCurrentWorkspaceID());
198 }
199 }
200
201 Basemenu::update();
202 }
203
204
205 void Windowmenu::SendtoWorkspacemenu::show(void) {
206 update();
207
208 Basemenu::show();
209 }
This page took 0.041855 seconds and 4 git commands to generate.