]> Dogcows Code - chaz/openbox/blob - src/Windowmenu.cc
import from 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 BasemenuItem *item = find(index);
94
95 hide();
96 switch (item->function()) {
97 case BScreen::WindowShade:
98 window->shade();
99 break;
100
101 case BScreen::WindowIconify:
102 window->iconify();
103 break;
104
105 case BScreen::WindowMaximize:
106 window->maximize(button);
107 break;
108
109 case BScreen::WindowClose:
110 window->close();
111 break;
112
113 case BScreen::WindowRaise: {
114 Workspace *wkspc = getScreen()->getWorkspace(window->getWorkspaceNumber());
115 wkspc->raiseWindow(window);
116 }
117 break;
118
119 case BScreen::WindowLower: {
120 Workspace *wkspc = getScreen()->getWorkspace(window->getWorkspaceNumber());
121 wkspc->lowerWindow(window);
122 }
123 break;
124
125 case BScreen::WindowStick:
126 window->stick();
127 break;
128
129 case BScreen::WindowKill:
130 XKillClient(getScreen()->getBaseDisplay()->getXDisplay(),
131 window->getClientWindow());
132 break;
133 }
134 }
135
136
137 void Windowmenu::reconfigure(void) {
138 setItemEnabled(1, window->hasTitlebar());
139 setItemEnabled(2, window->isIconifiable());
140 setItemEnabled(3, window->isMaximizable());
141 setItemEnabled(8, window->isClosable());
142
143 sendToMenu->reconfigure();
144
145 Basemenu::reconfigure();
146 }
147
148
149 Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu *w)
150 : Basemenu(w->getScreen()) {
151
152 window = w->window;
153
154 setTitleVisibility(False);
155 setMovable(False);
156 setInternalMenu();
157 update();
158 }
159
160
161 void Windowmenu::SendtoWorkspacemenu::itemSelected(int button,
162 unsigned int index) {
163 if (button > 2) return;
164
165 if (index <= getScreen()->getWorkspaceCount()) {
166 if (index == getScreen()->getCurrentWorkspaceID()) return;
167 if (window->isStuck()) window->stick();
168
169 if (button == 1) window->withdraw();
170 getScreen()->reassociateWindow(window, index, True);
171 if (button == 2) getScreen()->changeWorkspaceID(index);
172 }
173 hide();
174 }
175
176
177 void Windowmenu::SendtoWorkspacemenu::update(void) {
178 unsigned int i, r = getCount(),
179 workspace_count = getScreen()->getWorkspaceCount();
180 if (r > workspace_count) {
181 for (i = r; i < workspace_count; ++i)
182 remove(0);
183 r = getCount();
184 }
185
186 for (i = 0; i < workspace_count; ++i) {
187 if (r < workspace_count) {
188 insert(getScreen()->getWorkspace(i)->getName());
189 ++r;
190 } else {
191 changeItemLabel(i, getScreen()->getWorkspace(i)->getName());
192 }
193 }
194
195 Basemenu::update();
196 }
197
198
199 void Windowmenu::SendtoWorkspacemenu::show(void) {
200 update();
201
202 Basemenu::show();
203 }
This page took 0.044296 seconds and 5 git commands to generate.