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)
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:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
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.
25 # include "../config.h"
26 #endif // HAVE_CONFIG_H
31 #endif // HAVE_STRING_H
35 #include "blackbox.hh"
38 #include "Windowmenu.hh"
39 #include "Workspace.hh"
42 Windowmenu::Windowmenu(BlackboxWindow *win) : Basemenu(win->getScreen()) {
45 setTitleVisibility(False);
49 sendToMenu = new SendtoWorkspacemenu(this);
50 insert(i18n(WindowmenuSet, WindowmenuSendTo, "Send To ..."),
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"),
66 insert(i18n(WindowmenuSet, WindowmenuClose, "Close"),
67 BScreen::WindowClose);
71 setItemEnabled(1, window->hasTitlebar());
72 setItemEnabled(2, window->isIconifiable());
73 setItemEnabled(3, window->isMaximizable());
74 setItemEnabled(8, window->isClosable());
78 Windowmenu::~Windowmenu(void) {
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());
92 void Windowmenu::itemSelected(int button, unsigned int index) {
96 BasemenuItem *item = find(index);
99 switch (item->function()) {
100 case BScreen::WindowShade:
104 case BScreen::WindowIconify:
108 case BScreen::WindowMaximize:
109 window->maximize(1); // full maximize
112 case BScreen::WindowClose:
116 case BScreen::WindowRaise: {
118 getScreen()->getWorkspace(window->getWorkspaceNumber());
119 wkspc->raiseWindow(window);
123 case BScreen::WindowLower: {
125 getScreen()->getWorkspace(window->getWorkspaceNumber());
126 wkspc->lowerWindow(window);
130 case BScreen::WindowStick:
134 case BScreen::WindowKill:
135 XKillClient(getScreen()->getBaseDisplay()->getXDisplay(),
136 window->getClientWindow());
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());
148 sendToMenu->reconfigure();
150 Basemenu::reconfigure();
154 Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu *w)
155 : Basemenu(w->getScreen()) {
159 setTitleVisibility(False);
166 void Windowmenu::SendtoWorkspacemenu::itemSelected(int button,
167 unsigned int index) {
168 if (button > 2) return;
170 if (index <= getScreen()->getWorkspaceCount()) {
171 if (index == getScreen()->getCurrentWorkspaceID()) return;
172 if (window->isStuck()) window->stick();
174 if (button == 1) window->withdraw();
175 getScreen()->reassociateWindow(window, index, True);
176 if (button == 2) getScreen()->changeWorkspaceID(index);
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)
191 for (i = 0; i < workspace_count; ++i) {
192 if (r < workspace_count) {
193 insert(getScreen()->getWorkspace(i)->getName());
196 changeItemLabel(i, getScreen()->getWorkspace(i)->getName());
197 setItemEnabled(i, i != getScreen()->getCurrentWorkspaceID());
205 void Windowmenu::SendtoWorkspacemenu::show(void) {