2002-05-25 00:29:44 +00:00
|
|
|
// -*- mode: C++; indent-tabs-mode: nil; -*-
|
|
|
|
// Windowmenu.cc for Blackbox - an X11 Window manager
|
|
|
|
// Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
|
2002-04-11 03:20:38 +00:00
|
|
|
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "../config.h"
|
|
|
|
#endif // HAVE_CONFIG_H
|
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
extern "C" {
|
|
|
|
#ifdef HAVE_STRING_H
|
2002-04-11 03:20:38 +00:00
|
|
|
# include <string.h>
|
2002-04-16 06:25:00 +00:00
|
|
|
#endif // HAVE_STRING_H
|
2002-05-25 00:29:44 +00:00
|
|
|
}
|
2002-04-11 03:20:38 +00:00
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
#include "i18n.hh"
|
|
|
|
#include "blackbox.hh"
|
|
|
|
#include "Screen.hh"
|
|
|
|
#include "Window.hh"
|
|
|
|
#include "Windowmenu.hh"
|
|
|
|
#include "Workspace.hh"
|
2002-04-11 03:20:38 +00:00
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
|
|
|
|
Windowmenu::Windowmenu(BlackboxWindow *win) : Basemenu(win->getScreen()) {
|
|
|
|
window = win;
|
2002-04-11 03:20:38 +00:00
|
|
|
|
|
|
|
setTitleVisibility(False);
|
|
|
|
setMovable(False);
|
|
|
|
setInternalMenu();
|
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
sendToMenu = new SendtoWorkspacemenu(this);
|
2002-05-16 22:35:59 +00:00
|
|
|
insert(i18n(WindowmenuSet, WindowmenuSendTo, "Send To ..."),
|
|
|
|
sendToMenu);
|
|
|
|
insert(i18n(WindowmenuSet, WindowmenuShade, "Shade"),
|
|
|
|
BScreen::WindowShade);
|
|
|
|
insert(i18n(WindowmenuSet, WindowmenuIconify, "Iconify"),
|
|
|
|
BScreen::WindowIconify);
|
|
|
|
insert(i18n(WindowmenuSet, WindowmenuMaximize, "Maximize"),
|
|
|
|
BScreen::WindowMaximize);
|
|
|
|
insert(i18n(WindowmenuSet, WindowmenuRaise,"Raise"),
|
|
|
|
BScreen::WindowRaise);
|
|
|
|
insert(i18n(WindowmenuSet, WindowmenuLower, "Lower"),
|
|
|
|
BScreen::WindowLower);
|
|
|
|
insert(i18n(WindowmenuSet, WindowmenuStick, "Stick"),
|
|
|
|
BScreen::WindowStick);
|
|
|
|
insert(i18n(WindowmenuSet, WindowmenuKillClient, "Kill Client"),
|
|
|
|
BScreen::WindowKill);
|
|
|
|
insert(i18n(WindowmenuSet, WindowmenuClose, "Close"),
|
|
|
|
BScreen::WindowClose);
|
2002-04-11 03:20:38 +00:00
|
|
|
|
|
|
|
update();
|
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
setItemEnabled(1, window->hasTitlebar());
|
|
|
|
setItemEnabled(2, window->isIconifiable());
|
|
|
|
setItemEnabled(3, window->isMaximizable());
|
|
|
|
setItemEnabled(8, window->isClosable());
|
2002-04-11 03:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Windowmenu::~Windowmenu(void) {
|
|
|
|
delete sendToMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Windowmenu::show(void) {
|
2002-05-25 00:29:44 +00:00
|
|
|
if (isItemEnabled(1)) setItemSelected(1, window->isShaded());
|
|
|
|
if (isItemEnabled(3)) setItemSelected(3, window->isMaximized());
|
|
|
|
if (isItemEnabled(6)) setItemSelected(6, window->isStuck());
|
2002-04-11 03:20:38 +00:00
|
|
|
|
|
|
|
Basemenu::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
void Windowmenu::itemSelected(int button, unsigned int index) {
|
2002-05-27 03:55:18 +00:00
|
|
|
if (button != 1)
|
|
|
|
return;
|
2002-06-30 09:53:52 +00:00
|
|
|
|
2002-04-11 03:20:38 +00:00
|
|
|
BasemenuItem *item = find(index);
|
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
hide();
|
|
|
|
switch (item->function()) {
|
|
|
|
case BScreen::WindowShade:
|
|
|
|
window->shade();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BScreen::WindowIconify:
|
|
|
|
window->iconify();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BScreen::WindowMaximize:
|
2002-05-27 03:55:18 +00:00
|
|
|
window->maximize(1); // full maximize
|
2002-05-25 00:29:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BScreen::WindowClose:
|
|
|
|
window->close();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BScreen::WindowRaise: {
|
2002-06-30 09:53:52 +00:00
|
|
|
Workspace *wkspc =
|
|
|
|
getScreen()->getWorkspace(window->getWorkspaceNumber());
|
2002-05-25 00:29:44 +00:00
|
|
|
wkspc->raiseWindow(window);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BScreen::WindowLower: {
|
2002-06-30 09:53:52 +00:00
|
|
|
Workspace *wkspc =
|
|
|
|
getScreen()->getWorkspace(window->getWorkspaceNumber());
|
2002-05-25 00:29:44 +00:00
|
|
|
wkspc->lowerWindow(window);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BScreen::WindowStick:
|
|
|
|
window->stick();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BScreen::WindowKill:
|
|
|
|
XKillClient(getScreen()->getBaseDisplay()->getXDisplay(),
|
|
|
|
window->getClientWindow());
|
|
|
|
break;
|
2002-04-11 03:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Windowmenu::reconfigure(void) {
|
2002-05-25 00:29:44 +00:00
|
|
|
setItemEnabled(1, window->hasTitlebar());
|
|
|
|
setItemEnabled(2, window->isIconifiable());
|
|
|
|
setItemEnabled(3, window->isMaximizable());
|
|
|
|
setItemEnabled(8, window->isClosable());
|
2002-04-11 03:20:38 +00:00
|
|
|
|
|
|
|
sendToMenu->reconfigure();
|
|
|
|
|
|
|
|
Basemenu::reconfigure();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu *w)
|
|
|
|
: Basemenu(w->getScreen()) {
|
2002-04-11 03:20:38 +00:00
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
window = w->window;
|
2002-04-11 03:20:38 +00:00
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
setTitleVisibility(False);
|
|
|
|
setMovable(False);
|
|
|
|
setInternalMenu();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Windowmenu::SendtoWorkspacemenu::itemSelected(int button,
|
|
|
|
unsigned int index) {
|
2002-04-11 03:20:38 +00:00
|
|
|
if (button > 2) return;
|
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
if (index <= getScreen()->getWorkspaceCount()) {
|
|
|
|
if (index == getScreen()->getCurrentWorkspaceID()) return;
|
|
|
|
if (window->isStuck()) window->stick();
|
2002-04-11 03:20:38 +00:00
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
if (button == 1) window->withdraw();
|
|
|
|
getScreen()->reassociateWindow(window, index, True);
|
|
|
|
if (button == 2) getScreen()->changeWorkspaceID(index);
|
2002-04-11 03:20:38 +00:00
|
|
|
}
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Windowmenu::SendtoWorkspacemenu::update(void) {
|
2002-05-25 00:29:44 +00:00
|
|
|
unsigned int i, r = getCount(),
|
|
|
|
workspace_count = getScreen()->getWorkspaceCount();
|
2002-08-20 15:38:51 +00:00
|
|
|
while (r > workspace_count) {
|
|
|
|
remove(0);
|
2002-05-25 00:29:44 +00:00
|
|
|
r = getCount();
|
|
|
|
}
|
2002-04-11 03:20:38 +00:00
|
|
|
|
2002-05-25 00:29:44 +00:00
|
|
|
for (i = 0; i < workspace_count; ++i) {
|
|
|
|
if (r < workspace_count) {
|
|
|
|
insert(getScreen()->getWorkspace(i)->getName());
|
|
|
|
++r;
|
|
|
|
} else {
|
|
|
|
changeItemLabel(i, getScreen()->getWorkspace(i)->getName());
|
2002-05-30 04:35:22 +00:00
|
|
|
setItemEnabled(i, i != getScreen()->getCurrentWorkspaceID());
|
2002-05-25 00:29:44 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-11 03:20:38 +00:00
|
|
|
|
|
|
|
Basemenu::update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Windowmenu::SendtoWorkspacemenu::show(void) {
|
|
|
|
update();
|
|
|
|
|
|
|
|
Basemenu::show();
|
|
|
|
}
|