1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Slitmenu.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 "Slitmenu.hh"
26 #include "Screen.hh"
27 #include "Slit.hh"
28 
29 #include <Unicode.hh>
30 
31 
32 class SlitDirectionmenu : public bt::Menu {
33 public:
34   SlitDirectionmenu(bt::Application &app, unsigned int screen,
35 		    BScreen *bscreen);
36 
37   void refresh(void);
38 
39 protected:
40   void itemClicked(unsigned int id, unsigned int button);
41 
42 private:
43   BScreen *_bscreen;
44 };
45 
46 
47 class SlitPlacementmenu : public bt::Menu {
48 public:
49  SlitPlacementmenu(bt::Application &app, unsigned int screen,
50 		   BScreen *bscreen);
51 
52   void refresh(void);
53 
54 protected:
55   void itemClicked(unsigned int id, unsigned int button);
56 
57 private:
58   BScreen *_bscreen;
59 };
60 
61 
62 enum {
63   Direction,
64   Placement,
65   AlwaysOnTop,
66   AutoHide
67 };
68 
Slitmenu(bt::Application & app,unsigned int screen,BScreen * bscreen)69 Slitmenu::Slitmenu(bt::Application &app, unsigned int screen, BScreen *bscreen)
70   : bt::Menu(app, screen), _bscreen(bscreen)
71 {
72   setTitle(bt::toUnicode("Slit Options"));
73   showTitle();
74 
75   insertItem(bt::toUnicode("Direction"), new SlitDirectionmenu(app, screen, bscreen),
76              Direction);
77   insertItem(bt::toUnicode("Placement"), new SlitPlacementmenu(app, screen, bscreen),
78              Placement);
79   insertSeparator();
80   insertItem(bt::toUnicode("Always on top"), AlwaysOnTop);
81   insertItem(bt::toUnicode("Auto hide"), AutoHide);
82 }
83 
84 
refresh(void)85 void Slitmenu::refresh(void) {
86   const SlitOptions &options = _bscreen->resource().slitOptions();
87   setItemChecked(AlwaysOnTop, options.always_on_top);
88   setItemChecked(AutoHide, options.auto_hide);
89 }
90 
91 
itemClicked(unsigned int id,unsigned int button)92 void Slitmenu::itemClicked(unsigned int id, unsigned int button) {
93   if (button != 1)
94     return;
95 
96   Slit *slit = _bscreen->slit();
97   SlitOptions &options =
98     const_cast<SlitOptions &>(_bscreen->resource().slitOptions());
99 
100   switch (id) {
101   case AlwaysOnTop:
102     options.always_on_top = !options.always_on_top;
103     _bscreen->saveResource();
104     if (slit) {
105       StackingList::Layer new_layer = (options.always_on_top
106                                        ? StackingList::LayerAbove
107                                        : StackingList::LayerNormal);
108       _bscreen->stackingList().changeLayer(slit, new_layer);
109       _bscreen->restackWindows();
110     }
111     break;
112 
113   case AutoHide:
114     options.auto_hide = !options.auto_hide;
115     _bscreen->saveResource();
116     if (slit)
117       slit->toggleAutoHide();
118     break;
119 
120   default:
121     return;
122   } // switch
123 }
124 
125 
SlitDirectionmenu(bt::Application & app,unsigned int screen,BScreen * bscreen)126 SlitDirectionmenu::SlitDirectionmenu(bt::Application &app, unsigned int screen,
127                                      BScreen *bscreen)
128   : bt::Menu(app, screen), _bscreen(bscreen)
129 {
130   setTitle(bt::toUnicode("Slit Direction"));
131   showTitle();
132 
133   insertItem(bt::toUnicode("Horizontal"), Slit::Horizontal);
134   insertItem(bt::toUnicode("Vertical"), Slit::Vertical);
135 }
136 
137 
refresh(void)138 void SlitDirectionmenu::refresh(void) {
139   const SlitOptions &options =_bscreen->resource().slitOptions();
140   setItemChecked(Slit::Horizontal, options.direction == Slit::Horizontal);
141   setItemChecked(Slit::Vertical, options.direction == Slit::Vertical);
142 }
143 
144 
itemClicked(unsigned int id,unsigned int button)145 void SlitDirectionmenu::itemClicked(unsigned int id, unsigned int button) {
146   if (button != 1)
147     return;
148 
149   Slit *slit = _bscreen->slit();
150   SlitOptions &options =
151     const_cast<SlitOptions &>(_bscreen->resource().slitOptions());
152 
153   options.direction = id;
154   _bscreen->saveResource();
155   if (slit)
156     slit->reconfigure();
157 }
158 
159 
SlitPlacementmenu(bt::Application & app,unsigned int screen,BScreen * bscreen)160 SlitPlacementmenu::SlitPlacementmenu(bt::Application &app, unsigned int screen,
161                                      BScreen *bscreen)
162   : bt::Menu(app, screen), _bscreen(bscreen)
163 {
164   setTitle(bt::toUnicode("Slit Placement"));
165   showTitle();
166 
167   insertItem(bt::toUnicode("Top Left"),      Slit::TopLeft);
168   insertItem(bt::toUnicode("Center Left"),   Slit::CenterLeft);
169   insertItem(bt::toUnicode("Bottom Left"),   Slit::BottomLeft);
170   insertSeparator();
171   insertItem(bt::toUnicode("Top Center"),    Slit::TopCenter);
172   insertItem(bt::toUnicode("Bottom Center"), Slit::BottomCenter);
173   insertSeparator();
174   insertItem(bt::toUnicode("Top Right"),     Slit::TopRight);
175   insertItem(bt::toUnicode("Center Right"),  Slit::CenterRight);
176   insertItem(bt::toUnicode("Bottom Right"),  Slit::BottomRight);
177 }
178 
179 
refresh(void)180 void SlitPlacementmenu::refresh(void) {
181   const SlitOptions &options = _bscreen->resource().slitOptions();
182   setItemChecked(Slit::TopLeft,      options.placement == Slit::TopLeft);
183   setItemChecked(Slit::CenterLeft,   options.placement == Slit::CenterLeft);
184   setItemChecked(Slit::BottomLeft,   options.placement == Slit::BottomLeft);
185   setItemChecked(Slit::TopCenter,    options.placement == Slit::TopCenter);
186   setItemChecked(Slit::BottomCenter, options.placement == Slit::BottomCenter);
187   setItemChecked(Slit::TopRight,     options.placement == Slit::TopRight);
188   setItemChecked(Slit::CenterRight,  options.placement == Slit::CenterRight);
189   setItemChecked(Slit::BottomRight,  options.placement == Slit::BottomRight);
190 }
191 
192 
itemClicked(unsigned int id,unsigned int button)193 void SlitPlacementmenu::itemClicked(unsigned int id, unsigned int button) {
194   if (button != 1)
195     return;
196 
197   Slit *slit = _bscreen->slit();
198   SlitOptions &options =
199     const_cast<SlitOptions &>(_bscreen->resource().slitOptions());
200 
201   options.placement = id;
202   _bscreen->saveResource();
203   if (slit)
204     slit->reconfigure();
205 }
206