]> Dogcows Code - chaz/openbox/blob - src/XDisplay.cc
added the X classes to the build process though they aren't sued by anything else...
[chaz/openbox] / src / XDisplay.cc
1 // XDisplay.cc for Openbox
2 // Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22 #ifdef HAVE_CONFIG_H
23 # include "../config.h"
24 #endif
25
26 #ifdef HAVE_UNNISTD_H
27 # include <unistd.h>
28 #endif
29
30 #ifdef HAVE_FCNTL_H
31 # include <fcntl.h>
32 #endif
33
34 #ifdef SHAPE
35 # include <X11/extensions/shape.h>
36 #endif
37
38 #include "XDisplay.h"
39 #include "XScreen.h"
40 #include "Util.h"
41 #include <iostream>
42 #include <algorithm>
43
44 using std::cerr;
45
46 int XDisplay::XErrorHandler(Display *d, XErrorEvent *e) {
47 d=d;e=e;
48 return 0;
49 }
50
51
52 XDisplay::XDisplay(const char *dpyname) {
53 _grabs = 0;
54 _hasshape = false;
55
56 _display = XOpenDisplay(dpyname);
57 if (_display == NULL) {
58 cerr << "Could not open display. Connection to X server failed.\n";
59 ::exit(2);
60 }
61 if (-1 == fcntl(ConnectionNumber(_display), F_SETFD, 1)) {
62 cerr << "Could not mark display connection as close-on-exec.\n";
63 ::exit(2);
64 }
65 _name = XDisplayName(dpyname);
66
67 XSetErrorHandler(XErrorHandler);
68
69 #ifdef SHAPE
70 int waste;
71 _hasshape = XShapeQueryExtension(_display, &_shape_event_base, &waste);
72 #endif // SHAPE
73
74 const unsigned int scount = ScreenCount(_display);
75 _screens.reserve(scount);
76 for (unsigned int s = 0; s < scount; s++)
77 _screens.push_back(new XScreen(this, s));
78 }
79
80
81 XDisplay::~XDisplay() {
82 std::for_each(_screens.begin(), _screens.end(), PointerAssassin());
83 XCloseDisplay(_display);
84 }
85
86
87 /*
88 * Return information about a screen.
89 */
90 XScreen *XDisplay::screen(unsigned int s) const {
91 ASSERT(s < _screens.size());
92 return _screens[s];
93 }
94
95
96 /*
97 * Grab the X server
98 */
99 void XDisplay::grab() {
100 if (_grabs++ == 0)
101 XGrabServer(_display);
102 }
103
104
105 /*
106 * Release the X server from a grab
107 */
108 void XDisplay::ungrab() {
109 if (--_grabs == 0)
110 XUngrabServer(_display);
111 }
This page took 0.037197 seconds and 4 git commands to generate.