1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Workspacemenu.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000, 2002 - 2005
5 //         Bradley T Hughes <bhughes at trolltech.com>
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
24 
25 #include "Workspacemenu.hh"
26 #include "Clientmenu.hh"
27 #include "Iconmenu.hh"
28 #include "Screen.hh"
29 #include "Workspace.hh"
30 
31 #include <Unicode.hh>
32 
33 #include <assert.h>
34 
35 
36 enum {
37   Icons,
38   NewWorkspace,
39   RemoveLastWorkspace,
40   WorkspaceIDDelta
41 };
42 
Workspacemenu(bt::Application & app,unsigned int screen,BScreen * bscreen)43 Workspacemenu::Workspacemenu(bt::Application &app, unsigned int screen,
44                              BScreen *bscreen)
45   : bt::Menu(app, screen), _bscreen(bscreen) {
46   setAutoDelete(false);
47   setTitle(bt::toUnicode("Workspaces"));
48   showTitle();
49 
50   insertSeparator();
51   insertItem(bt::toUnicode("New Workspace"), NewWorkspace);
52   insertItem(bt::toUnicode("Remove Last Workspace"), RemoveLastWorkspace);
53 }
54 
55 
insertWorkspace(Workspace * workspace)56 void Workspacemenu::insertWorkspace(Workspace *workspace) {
57   insertItem(workspace->name(), workspace->menu(),
58              workspace->id() + WorkspaceIDDelta, count() - 3);
59 }
60 
61 
removeWorkspace(unsigned int id)62 void Workspacemenu::removeWorkspace(unsigned int id)
63 { removeItem(id + WorkspaceIDDelta); }
64 
65 
setWorkspaceChecked(unsigned int id,bool checked)66 void Workspacemenu::setWorkspaceChecked(unsigned int id, bool checked)
67 { setItemChecked(id + WorkspaceIDDelta, checked); }
68 
69 
insertIconMenu(Iconmenu * iconmenu)70 void Workspacemenu::insertIconMenu(Iconmenu *iconmenu) {
71   insertItem(bt::toUnicode("Iconified Windows"), iconmenu, Icons, 0);
72   insertSeparator(1);
73 }
74 
75 
itemClicked(unsigned int id,unsigned int)76 void Workspacemenu::itemClicked(unsigned int id, unsigned int) {
77   switch (id) {
78   case NewWorkspace:
79     _bscreen->addWorkspace();
80     _bscreen->resource().setWorkspaceCount(_bscreen->workspaceCount());
81     _bscreen->saveResource();
82     break;
83 
84   case RemoveLastWorkspace:
85     _bscreen->removeLastWorkspace();
86     _bscreen->resource().setWorkspaceCount(_bscreen->workspaceCount());
87     _bscreen->saveResource();
88     break;
89 
90   case Icons:
91     break;
92 
93   default:
94     id -= WorkspaceIDDelta;
95     assert(id < _bscreen->workspaceCount());
96     if (_bscreen->currentWorkspace() != id) {
97       _bscreen->setCurrentWorkspace(id);
98       hideAll();
99     }
100     break;
101   } // switch
102 }
103