]> Dogcows Code - chaz/openbox/blob - src/Slit.cc
set the button windows to None when they are destroyed so we know they are no longer...
[chaz/openbox] / src / Slit.cc
1 // Slit.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef HAVE_CONFIG_H
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #ifdef SLIT
34
35 #include <X11/keysym.h>
36
37 #include "i18n.h"
38 #include "openbox.h"
39 #include "Image.h"
40 #include "Screen.h"
41 #include "Slit.h"
42 #include "Toolbar.h"
43
44 #include <strstream>
45 #include <string>
46 using std::ends;
47
48 Slit::Slit(BScreen &scr, Resource &conf) : openbox(scr.getOpenbox()),
49 screen(scr), config(conf)
50 {
51 load();
52
53 display = screen.getBaseDisplay().getXDisplay();
54 frame.window = frame.pixmap = None;
55
56 timer = new BTimer(openbox, *this);
57 timer->setTimeout(openbox.getAutoRaiseDelay());
58 timer->fireOnce(True);
59
60 slitmenu = new Slitmenu(*this);
61
62 XSetWindowAttributes attrib;
63 unsigned long create_mask = CWBackPixmap | CWBackPixel | CWBorderPixel |
64 CWColormap | CWOverrideRedirect | CWEventMask;
65 attrib.background_pixmap = None;
66 attrib.background_pixel = attrib.border_pixel =
67 screen.getBorderColor()->getPixel();
68 attrib.colormap = screen.getColormap();
69 attrib.override_redirect = True;
70 attrib.event_mask = SubstructureRedirectMask | ButtonPressMask |
71 EnterWindowMask | LeaveWindowMask;
72
73 frame.area = Rect(0, 0, 1, 1);
74
75 frame.window =
76 XCreateWindow(display, screen.getRootWindow(),
77 frame.area.x(), frame.area.y(),
78 frame.area.w(), frame.area.h(), screen.getBorderWidth(),
79 screen.getDepth(), InputOutput, screen.getVisual(),
80 create_mask, &attrib);
81 openbox.saveSlitSearch(frame.window, this);
82
83 reconfigure();
84 }
85
86
87 Slit::~Slit() {
88 openbox.grab();
89
90 if (timer->isTiming()) timer->stop();
91 delete timer;
92
93 clientList.clear();
94
95 delete slitmenu;
96
97 screen.getImageControl()->removeImage(frame.pixmap);
98
99 openbox.removeSlitSearch(frame.window);
100
101 XDestroyWindow(display, frame.window);
102
103 openbox.ungrab();
104 }
105
106
107 void Slit::addClient(Window w) {
108 openbox.grab();
109
110 if (openbox.validateWindow(w)) {
111 SlitClient *client = new SlitClient;
112 client->client_window = w;
113
114 XWMHints *wmhints = XGetWMHints(display, w);
115
116 if (wmhints) {
117 if ((wmhints->flags & IconWindowHint) &&
118 (wmhints->icon_window != None)) {
119 XMoveWindow(display, client->client_window, screen.size().w() + 10,
120 screen.size().h() + 10);
121 XMapWindow(display, client->client_window);
122
123 client->icon_window = wmhints->icon_window;
124 client->window = client->icon_window;
125 } else {
126 client->icon_window = None;
127 client->window = client->client_window;
128 }
129
130 XFree(wmhints);
131 } else {
132 client->icon_window = None;
133 client->window = client->client_window;
134 }
135
136 XWindowAttributes attrib;
137 if (XGetWindowAttributes(display, client->window, &attrib)) {
138 client->width = attrib.width;
139 client->height = attrib.height;
140 } else {
141 client->width = client->height = 64;
142 }
143
144 XSetWindowBorderWidth(display, client->window, 0);
145
146 XSelectInput(display, frame.window, NoEventMask);
147 XSelectInput(display, client->window, NoEventMask);
148
149 XReparentWindow(display, client->window, frame.window, 0, 0);
150 XMapRaised(display, client->window);
151 XChangeSaveSet(display, client->window, SetModeInsert);
152
153 XSelectInput(display, frame.window, SubstructureRedirectMask |
154 ButtonPressMask | EnterWindowMask | LeaveWindowMask);
155 XSelectInput(display, client->window, StructureNotifyMask |
156 SubstructureNotifyMask | EnterWindowMask);
157 XFlush(display);
158
159 clientList.push_back(client);
160
161 openbox.saveSlitSearch(client->client_window, this);
162 openbox.saveSlitSearch(client->icon_window, this);
163 reconfigure();
164 }
165
166 openbox.ungrab();
167 }
168
169
170 void Slit::removeClient(SlitClient *client, Bool remap) {
171 openbox.removeSlitSearch(client->client_window);
172 openbox.removeSlitSearch(client->icon_window);
173
174 clientList.remove(client);
175
176 screen.removeNetizen(client->window);
177
178 if (remap && openbox.validateWindow(client->window)) {
179 XSelectInput(display, frame.window, NoEventMask);
180 XSelectInput(display, client->window, NoEventMask);
181 XReparentWindow(display, client->window, screen.getRootWindow(),
182 client->x, client->y);
183 XChangeSaveSet(display, client->window, SetModeDelete);
184 XSelectInput(display, frame.window, SubstructureRedirectMask |
185 ButtonPressMask | EnterWindowMask | LeaveWindowMask);
186 XFlush(display);
187 }
188
189 delete client;
190 client = (SlitClient *) 0;
191 }
192
193
194 void Slit::removeClient(Window w, Bool remap) {
195 openbox.grab();
196
197 Bool reconf = False;
198
199 slitClientList::iterator it;
200 for (it = clientList.begin(); it != clientList.end(); it++)
201 if ((*it)->window == w) {
202 removeClient(*it, remap);
203 reconf = True;
204 break;
205 }
206
207 if (reconf)
208 reconfigure();
209
210 openbox.ungrab();
211 }
212
213 void Slit::setOnTop(bool b) {
214 m_ontop = b;
215 std::ostrstream s;
216 s << "session.screen" << screen.getScreenNumber() << ".slit.onTop" << ends;
217 config.setValue(s.str(), m_ontop ? "True" : "False");
218 s.rdbuf()->freeze(0);
219 }
220
221 void Slit::setAutoHide(bool b) {
222 m_autohide = b;
223 std::ostrstream s;
224 s << "session.screen" << screen.getScreenNumber() << ".slit.autoHide" << ends;
225 config.setValue(s.str(), m_autohide ? "True" : "False");
226 s.rdbuf()->freeze(0);
227 }
228
229 void Slit::setPlacement(int p) {
230 m_placement = p;
231 std::ostrstream s;
232 s << "session.screen" << screen.getScreenNumber() << ".slit.placement"
233 << ends;
234 const char *placement;
235 switch (m_placement) {
236 case TopLeft: placement = "TopLeft"; break;
237 case CenterLeft: placement = "CenterLeft"; break;
238 case BottomLeft: placement = "BottomLeft"; break;
239 case TopCenter: placement = "TopCenter"; break;
240 case BottomCenter: placement = "BottomCenter"; break;
241 case TopRight: placement = "TopRight"; break;
242 case BottomRight: placement = "BottomRight"; break;
243 case CenterRight: default: placement = "CenterRight"; break;
244 }
245 config.setValue(s.str(), placement);
246 s.rdbuf()->freeze(0);
247 }
248
249 void Slit::setDirection(int d) {
250 m_direction = d;
251 std::ostrstream s;
252 s << "session.screen" << screen.getScreenNumber() << ".slit.direction"
253 << ends;
254 config.setValue(s.str(),
255 m_direction == Horizontal ? "Horizontal" : "Vertical");
256 s.rdbuf()->freeze(0);
257 }
258
259 void Slit::save() {
260 setOnTop(m_ontop);
261 setAutoHide(m_autohide);
262 setPlacement(m_placement);
263 setDirection(m_direction);
264 }
265
266 void Slit::load() {
267 std::ostrstream rscreen, rname, rclass;
268 std::string s;
269 bool b;
270 rscreen << "session.screen" << screen.getScreenNumber() << '.' << ends;
271
272 rname << rscreen.str() << "slit.placement" << ends;
273 rclass << rscreen.str() << "Slit.Placement" << ends;
274 if (config.getValue(rname.str(), rclass.str(), s)) {
275 if (0 == strncasecmp(s.c_str(), "TopLeft", s.length()))
276 m_placement = TopLeft;
277 else if (0 == strncasecmp(s.c_str(), "CenterLeft", s.length()))
278 m_placement = CenterLeft;
279 else if (0 == strncasecmp(s.c_str(), "BottomLeft", s.length()))
280 m_placement = BottomLeft;
281 else if (0 == strncasecmp(s.c_str(), "TopCenter", s.length()))
282 m_placement = TopCenter;
283 else if (0 == strncasecmp(s.c_str(), "BottomCenter", s.length()))
284 m_placement = BottomCenter;
285 else if (0 == strncasecmp(s.c_str(), "TopRight", s.length()))
286 m_placement = TopRight;
287 else if (0 == strncasecmp(s.c_str(), "BottomRight", s.length()))
288 m_placement = BottomRight;
289 else if (0 == strncasecmp(s.c_str(), "CenterRight", s.length()))
290 m_placement = CenterRight;
291 } else
292 m_placement = CenterRight;
293
294 rname.seekp(0); rclass.seekp(0);
295 rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
296 rname << rscreen.str() << "slit.direction" << ends;
297 rclass << rscreen.str() << "Slit.Direction" << ends;
298 if (config.getValue(rname.str(), rclass.str(), s)) {
299 if (0 == strncasecmp(s.c_str(), "Horizontal", s.length()))
300 m_direction = Horizontal;
301 else if (0 == strncasecmp(s.c_str(), "Vertical", s.length()))
302 m_direction = Vertical;
303 } else
304 m_direction = Vertical;
305
306 rname.seekp(0); rclass.seekp(0);
307 rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
308 rname << rscreen.str() << "slit.onTop" << ends;
309 rclass << rscreen.str() << "Slit.OnTop" << ends;
310 if (config.getValue(rname.str(), rclass.str(), b))
311 m_ontop = b;
312 else
313 m_ontop = false;
314
315 rname.seekp(0); rclass.seekp(0);
316 rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
317 rname << rscreen.str() << "slit.autoHide" << ends;
318 rclass << rscreen.str() << "Slit.AutoHide" << ends;
319 if (config.getValue(rname.str(), rclass.str(), b))
320 m_hidden = m_autohide = b;
321 else
322 m_hidden = m_autohide = false;
323
324 rscreen.rdbuf()->freeze(0);
325 rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
326 }
327
328 void Slit::reconfigure(void) {
329 frame.area.setSize(0, 0);
330 slitClientList::const_iterator it;
331
332 switch (m_direction) {
333 case Vertical:
334 for (it = clientList.begin(); it != clientList.end(); it++) {
335 frame.area.setH(frame.area.h() + (*it)->height + screen.getBevelWidth());
336
337 if (frame.area.w() < (*it)->width)
338 frame.area.setW((*it)->width);
339 }
340
341 if (frame.area.w() < 1)
342 frame.area.setW(1);
343 else
344 frame.area.setW(frame.area.w() + (screen.getBevelWidth() * 2));
345
346 if (frame.area.h() < 1)
347 frame.area.setH(1);
348 else
349 frame.area.setH(frame.area.h() + screen.getBevelWidth());
350
351 break;
352
353 case Horizontal:
354 for (it = clientList.begin(); it != clientList.end(); it++) {
355 frame.area.setW(frame.area.w() + (*it)->width + screen.getBevelWidth());
356
357 if (frame.area.h() < (*it)->height)
358 frame.area.setH((*it)->height);
359 }
360
361 if (frame.area.w() < 1)
362 frame.area.setW(1);
363 else
364 frame.area.setW(frame.area.w() + screen.getBevelWidth());
365
366 if (frame.area.h() < 1)
367 frame.area.setH(1);
368 else
369 frame.area.setH(frame.area.h() + (screen.getBevelWidth() * 2));
370
371 break;
372 }
373
374 reposition();
375
376 XSetWindowBorderWidth(display ,frame.window, screen.getBorderWidth());
377 XSetWindowBorder(display, frame.window,
378 screen.getBorderColor()->getPixel());
379
380 if (! clientList.size())
381 XUnmapWindow(display, frame.window);
382 else
383 XMapWindow(display, frame.window);
384
385 Pixmap tmp = frame.pixmap;
386 BImageControl *image_ctrl = screen.getImageControl();
387 BTexture *texture = &(screen.getToolbarStyle()->toolbar);
388 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
389 frame.pixmap = None;
390 XSetWindowBackground(display, frame.window,
391 texture->getColor()->getPixel());
392 } else {
393 frame.pixmap = image_ctrl->renderImage(frame.area.w(), frame.area.h(),
394 texture);
395 XSetWindowBackgroundPixmap(display, frame.window, frame.pixmap);
396 }
397 if (tmp) image_ctrl->removeImage(tmp);
398 XClearWindow(display, frame.window);
399
400 int x, y;
401
402 switch (m_direction) {
403 case Vertical:
404 x = 0;
405 y = screen.getBevelWidth();
406
407 for (it = clientList.begin(); it != clientList.end(); it++) {
408 x = (frame.area.w() - (*it)->width) / 2;
409
410 XMoveResizeWindow(display, (*it)->window, x, y,
411 (*it)->width, (*it)->height);
412 XMapWindow(display, (*it)->window);
413
414 // for ICCCM compliance
415 (*it)->x = x;
416 (*it)->y = y;
417
418 XEvent event;
419 event.type = ConfigureNotify;
420
421 event.xconfigure.display = display;
422 event.xconfigure.event = (*it)->window;
423 event.xconfigure.window = (*it)->window;
424 event.xconfigure.x = x;
425 event.xconfigure.y = y;
426 event.xconfigure.width = (*it)->width;
427 event.xconfigure.height = (*it)->height;
428 event.xconfigure.border_width = 0;
429 event.xconfigure.above = frame.window;
430 event.xconfigure.override_redirect = False;
431
432 XSendEvent(display, (*it)->window, False, StructureNotifyMask, &event);
433
434 y += (*it)->height + screen.getBevelWidth();
435 }
436
437 break;
438
439 case Horizontal:
440 x = screen.getBevelWidth();
441 y = 0;
442
443 for (it = clientList.begin(); it != clientList.end(); it++) {
444 y = (frame.area.h() - (*it)->height) / 2;
445
446 XMoveResizeWindow(display, (*it)->window, x, y,
447 (*it)->width, (*it)->height);
448 XMapWindow(display, (*it)->window);
449
450 // for ICCCM compliance
451 (*it)->x = x;
452 (*it)->y = y;
453
454 XEvent event;
455 event.type = ConfigureNotify;
456
457 event.xconfigure.display = display;
458 event.xconfigure.event = (*it)->window;
459 event.xconfigure.window = (*it)->window;
460 event.xconfigure.x = x;
461 event.xconfigure.y = y;
462 event.xconfigure.width = (*it)->width;
463 event.xconfigure.height = (*it)->height;
464 event.xconfigure.border_width = 0;
465 event.xconfigure.above = frame.window;
466 event.xconfigure.override_redirect = False;
467
468 XSendEvent(display, (*it)->window, False, StructureNotifyMask, &event);
469
470 x += (*it)->width + screen.getBevelWidth();
471 }
472
473 break;
474 }
475
476 slitmenu->reconfigure();
477 }
478
479
480 void Slit::reposition(void) {
481 // place the slit in the appropriate place
482 switch (m_placement) {
483 case TopLeft:
484 frame.area.setOrigin(0, 0);
485 if (m_direction == Vertical) {
486 frame.hidden = Point(screen.getBevelWidth() - screen.getBorderWidth()
487 - frame.area.w(), 0);
488 } else {
489 frame.hidden = Point(0, screen.getBevelWidth() - screen.getBorderWidth()
490 - frame.area.h());
491 }
492 break;
493
494 case CenterLeft:
495 frame.area.setOrigin(0, (screen.size().h() - frame.area.h()) / 2);
496 frame.hidden = Point(screen.getBevelWidth() - screen.getBorderWidth()
497 - frame.area.w(), frame.area.y());
498 break;
499
500 case BottomLeft:
501 frame.area.setOrigin(0, screen.size().h() - frame.area.h()
502 - (screen.getBorderWidth() * 2));
503 if (m_direction == Vertical)
504 frame.hidden = Point(screen.getBevelWidth() - screen.getBorderWidth()
505 - frame.area.w(), frame.area.y());
506 else
507 frame.hidden = Point(0, screen.size().h() - screen.getBevelWidth()
508 - screen.getBorderWidth());
509 break;
510
511 case TopCenter:
512 frame.area.setOrigin((screen.size().w() - frame.area.w()) / 2, 0);
513 frame.hidden = Point(frame.area.x(), screen.getBevelWidth()
514 - screen.getBorderWidth() - frame.area.h());
515 break;
516
517 case BottomCenter:
518 frame.area.setOrigin((screen.size().w() - frame.area.w()) / 2,
519 screen.size().h() - frame.area.h()
520 - (screen.getBorderWidth() * 2));
521 frame.hidden = Point(frame.area.x(), screen.size().h()
522 - screen.getBevelWidth() - screen.getBorderWidth());
523 break;
524
525 case TopRight:
526 frame.area.setOrigin(screen.size().w() - frame.area.w()
527 - (screen.getBorderWidth() * 2), 0);
528 if (m_direction == Vertical)
529 frame.hidden = Point(screen.size().w() - screen.getBevelWidth()
530 - screen.getBorderWidth(), 0);
531 else
532 frame.hidden = Point(frame.area.x(), screen.getBevelWidth()
533 - screen.getBorderWidth() - frame.area.h());
534 break;
535
536 case CenterRight:
537 default:
538 frame.area.setOrigin(screen.size().w() - frame.area.w()
539 - (screen.getBorderWidth() * 2),
540 (screen.size().h() - frame.area.h()) / 2);
541 frame.hidden = Point(screen.size().w() - screen.getBevelWidth()
542 - screen.getBorderWidth(), frame.area.y());
543 break;
544
545 case BottomRight:
546 frame.area.setOrigin(screen.size().w() - frame.area.w()
547 - (screen.getBorderWidth() * 2),
548 screen.size().h() - frame.area.h()
549 - (screen.getBorderWidth() * 2));
550 if (m_direction == Vertical)
551 frame.hidden = Point(screen.size().w() - screen.getBevelWidth()
552 - screen.getBorderWidth(), frame.area.y());
553 else
554 frame.hidden = Point(frame.area.x(), screen.size().h() -
555 screen.getBevelWidth() - screen.getBorderWidth());
556 break;
557 }
558
559 Toolbar *tbar = screen.getToolbar();
560 int sw = frame.area.w() + (screen.getBorderWidth() * 2),
561 sh = frame.area.h() + (screen.getBorderWidth() * 2),
562 tw = tbar->area().w() + screen.getBorderWidth(),
563 th = tbar->area().h() + screen.getBorderWidth();
564
565 if (tbar->area().x() < frame.area.x() + sw &&
566 tbar->area().x() + tw > frame.area.x() &&
567 tbar->area().y() < frame.area.y() + sh &&
568 tbar->area().y() + th > frame.area.y()) {
569 if (frame.area.y() < th) {
570 frame.area.setY(frame.area.y() + tbar->getExposedHeight());
571 if (m_direction == Vertical)
572 frame.hidden.setY(frame.hidden.y() + tbar->getExposedHeight());
573 else
574 frame.hidden.setY(frame.area.y());
575 } else {
576 frame.area.setY(frame.area.y() - tbar->getExposedHeight());
577 if (m_direction == Vertical)
578 frame.hidden.setY(frame.area.y() - tbar->getExposedHeight());
579 else
580 frame.hidden.setY(frame.area.y());
581 }
582 }
583
584 if (m_hidden)
585 XMoveResizeWindow(display, frame.window, frame.hidden.x(),
586 frame.hidden.y(), frame.area.w(), frame.area.h());
587 else
588 XMoveResizeWindow(display, frame.window, frame.area.x(),
589 frame.area.y(), frame.area.w(), frame.area.h());
590 }
591
592
593 void Slit::shutdown(void) {
594 while (clientList.size())
595 removeClient(clientList.front());
596 }
597
598
599 void Slit::buttonPressEvent(XButtonEvent *e) {
600 if (e->window != frame.window) return;
601
602 if (e->button == Button1 && !m_ontop) {
603 Window w[1] = { frame.window };
604 screen.raiseWindows(w, 1);
605 } else if (e->button == Button2 && !m_ontop) {
606 XLowerWindow(display, frame.window);
607 } else if (e->button == Button3) {
608 if (! slitmenu->isVisible()) {
609 int x, y;
610
611 x = e->x_root - (slitmenu->getWidth() / 2);
612 y = e->y_root - (slitmenu->getHeight() / 2);
613
614 if (x < 0)
615 x = 0;
616 else if (x + slitmenu->getWidth() > screen.size().w())
617 x = screen.size().w() - slitmenu->getWidth();
618
619 if (y < 0)
620 y = 0;
621 else if (y + slitmenu->getHeight() > screen.size().h())
622 y = screen.size().h() - slitmenu->getHeight();
623
624 slitmenu->move(x, y);
625 slitmenu->show();
626 } else {
627 slitmenu->hide();
628 }
629 }
630 }
631
632
633 void Slit::enterNotifyEvent(XCrossingEvent *) {
634 if (!m_autohide)
635 return;
636
637 if (m_hidden) {
638 if (! timer->isTiming()) timer->start();
639 } else {
640 if (timer->isTiming()) timer->stop();
641 }
642 }
643
644
645 void Slit::leaveNotifyEvent(XCrossingEvent *) {
646 if (!m_autohide)
647 return;
648
649 if (m_hidden) {
650 if (timer->isTiming()) timer->stop();
651 } else if (! slitmenu->isVisible()) {
652 if (!timer->isTiming()) timer->start();
653 }
654 }
655
656
657 void Slit::configureRequestEvent(XConfigureRequestEvent *e) {
658 openbox.grab();
659
660 if (openbox.validateWindow(e->window)) {
661 Bool reconf = False;
662 XWindowChanges xwc;
663
664 xwc.x = e->x;
665 xwc.y = e->y;
666 xwc.width = e->width;
667 xwc.height = e->height;
668 xwc.border_width = 0;
669 xwc.sibling = e->above;
670 xwc.stack_mode = e->detail;
671
672 XConfigureWindow(display, e->window, e->value_mask, &xwc);
673
674 slitClientList::iterator it = clientList.begin();
675 for (; it != clientList.end(); it++) {
676 SlitClient *client = *it;
677 if (client->window == e->window)
678 if (client->width != ((unsigned) e->width) ||
679 client->height != ((unsigned) e->height)) {
680 client->width = (unsigned) e->width;
681 client->height = (unsigned) e->height;
682 reconf = True;
683 break;
684 }
685 }
686
687 if (reconf)
688 reconfigure();
689 }
690 openbox.ungrab();
691 }
692
693
694 void Slit::timeout(void) {
695 m_hidden = !m_hidden;
696 if (m_hidden)
697 XMoveWindow(display, frame.window, frame.hidden.x(), frame.hidden.y());
698 else
699 XMoveWindow(display, frame.window, frame.area.x(), frame.area.y());
700 }
701
702
703 Slitmenu::Slitmenu(Slit &sl) : Basemenu(sl.screen), slit(sl) {
704 setLabel(i18n->getMessage(SlitSet, SlitSlitTitle, "Slit"));
705 setInternalMenu();
706
707 directionmenu = new Directionmenu(*this);
708 placementmenu = new Placementmenu(*this);
709
710 insert(i18n->getMessage(CommonSet, CommonDirectionTitle, "Direction"),
711 directionmenu);
712 insert(i18n->getMessage(CommonSet, CommonPlacementTitle, "Placement"),
713 placementmenu);
714 insert(i18n->getMessage(CommonSet, CommonAlwaysOnTop, "Always on top"), 1);
715 insert(i18n->getMessage(CommonSet, CommonAutoHide, "Auto hide"), 2);
716
717 update();
718
719 setValues();
720 }
721
722 void Slitmenu::setValues() {
723 setItemSelected(2, slit.onTop());
724 setItemSelected(3, slit.autoHide());
725 }
726
727
728 Slitmenu::~Slitmenu(void) {
729 delete directionmenu;
730 delete placementmenu;
731 }
732
733
734 void Slitmenu::itemSelected(int button, int index) {
735 if (button != 1)
736 return;
737
738 BasemenuItem *item = find(index);
739 if (! item) return;
740
741 switch (item->function()) {
742 case 1: { // always on top
743 bool change = ((slit.onTop()) ? false : true);
744 slit.setOnTop(change);
745 setItemSelected(2, change);
746
747 if (slit.onTop()) slit.screen.raiseWindows((Window *) 0, 0);
748 break;
749 }
750
751 case 2: { // auto hide
752 Bool change = ((slit.autoHide()) ? false : true);
753 slit.setAutoHide(change);
754 setItemSelected(3, change);
755
756 break;
757 }
758 } // switch
759 }
760
761
762 void Slitmenu::internal_hide(void) {
763 Basemenu::internal_hide();
764 if (slit.autoHide())
765 slit.timeout();
766 }
767
768
769 void Slitmenu::reconfigure(void) {
770 setValues();
771 directionmenu->reconfigure();
772 placementmenu->reconfigure();
773
774 Basemenu::reconfigure();
775 }
776
777
778 Slitmenu::Directionmenu::Directionmenu(Slitmenu &sm)
779 : Basemenu(sm.slit.screen), slitmenu(sm) {
780 setLabel(i18n->getMessage(SlitSet, SlitSlitDirection, "Slit Direction"));
781 setInternalMenu();
782
783 insert(i18n->getMessage(CommonSet, CommonDirectionHoriz, "Horizontal"),
784 Slit::Horizontal);
785 insert(i18n->getMessage(CommonSet, CommonDirectionVert, "Vertical"),
786 Slit::Vertical);
787
788 update();
789
790 setValues();
791 }
792
793
794 void Slitmenu::Directionmenu::setValues() {
795 if (slitmenu.slit.direction() == Slit::Horizontal)
796 setItemSelected(0, True);
797 else
798 setItemSelected(1, True);
799 }
800
801 void Slitmenu::Directionmenu::reconfigure() {
802 setValues();
803 }
804
805
806 void Slitmenu::Directionmenu::itemSelected(int button, int index) {
807 if (button != 1)
808 return;
809
810 BasemenuItem *item = find(index);
811 if (! item) return;
812
813 slitmenu.slit.setDirection(item->function());
814
815 if (item->function() == Slit::Horizontal) {
816 setItemSelected(0, True);
817 setItemSelected(1, False);
818 } else {
819 setItemSelected(0, False);
820 setItemSelected(1, True);
821 }
822
823 hide();
824 slitmenu.slit.reconfigure();
825 }
826
827
828 Slitmenu::Placementmenu::Placementmenu(Slitmenu &sm)
829 : Basemenu(sm.slit.screen), slitmenu(sm) {
830
831 setLabel(i18n->getMessage(SlitSet, SlitSlitPlacement, "Slit Placement"));
832 setMinimumSublevels(3);
833 setInternalMenu();
834
835 insert(i18n->getMessage(CommonSet, CommonPlacementTopLeft, "Top Left"),
836 Slit::TopLeft);
837 insert(i18n->getMessage(CommonSet, CommonPlacementCenterLeft, "Center Left"),
838 Slit::CenterLeft);
839 insert(i18n->getMessage(CommonSet, CommonPlacementBottomLeft, "Bottom Left"),
840 Slit::BottomLeft);
841 insert(i18n->getMessage(CommonSet, CommonPlacementTopCenter, "Top Center"),
842 Slit::TopCenter);
843 insert("");
844 insert(i18n->getMessage(CommonSet, CommonPlacementBottomCenter,
845 "Bottom Center"),
846 Slit::BottomCenter);
847 insert(i18n->getMessage(CommonSet, CommonPlacementTopRight, "Top Right"),
848 Slit::TopRight);
849 insert(i18n->getMessage(CommonSet, CommonPlacementCenterRight,
850 "Center Right"),
851 Slit::CenterRight);
852 insert(i18n->getMessage(CommonSet, CommonPlacementBottomRight,
853 "Bottom Right"),
854 Slit::BottomRight);
855
856 update();
857 }
858
859
860 void Slitmenu::Placementmenu::itemSelected(int button, int index) {
861 if (button != 1)
862 return;
863
864 BasemenuItem *item = find(index);
865 if (! (item && item->function())) return;
866
867 slitmenu.slit.setPlacement(item->function());
868 hide();
869 slitmenu.slit.reconfigure();
870 }
871
872 #endif // SLIT
This page took 0.072991 seconds and 4 git commands to generate.