]>
Dogcows Code - chaz/openbox/blob - otk/display.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
8 #include "screeninfo.hh"
12 #include <X11/keysym.h>
15 #include <X11/extensions/shape.h>
20 #endif // HAVE_STDIO_H
24 #endif // HAVE_STDLIB_H
28 #endif // HAVE_SIGNAL_H
32 #endif // HAVE_FCNTL_H
35 # include <sys/types.h>
37 #endif // HAVE_UNISTD_H
40 #define _(str) gettext(str)
46 Display
*OBDisplay::display
= (Display
*) 0;
47 bool OBDisplay::_shape
= false;
48 int OBDisplay::_shape_event_basep
= 0;
49 bool OBDisplay::_xinerama
= false;
50 int OBDisplay::_xinerama_event_basep
= 0;
51 unsigned int OBDisplay::_mask_list
[8];
52 OBDisplay::ScreenInfoList
OBDisplay::_screenInfoList
;
53 BGCCache
*OBDisplay::_gccache
= (BGCCache
*) 0;
56 int OBDisplay::xerrorHandler(Display
*d
, XErrorEvent
*e
)
61 //if (e->error_code != BadWindow)
63 XGetErrorText(d
, e
->error_code
, errtxt
, 128);
64 printf("X Error: %s\n", errtxt
);
75 void OBDisplay::initialize(char *name
)
81 if (!(display
= XOpenDisplay(name
))) {
82 printf(_("Unable to open connection to the X server. Please set the \n\
83 DISPLAY environment variable approriately, or use the '-display' command \n\
84 line argument.\n\n"));
87 if (fcntl(ConnectionNumber(display
), F_SETFD
, 1) == -1) {
88 printf(_("Couldn't mark display connection as close-on-exec.\n\n"));
92 // set our error handler for X errors
93 XSetErrorHandler(xerrorHandler
);
95 // set the DISPLAY environment variable for any lauched children, to the
96 // display we're using, so they open in the right place.
97 // XXX rm -> std::string dtmp = "DISPLAY=" + DisplayString(display);
98 if (putenv(const_cast<char*>((std::string("DISPLAY=") +
99 DisplayString(display
)).c_str()))) {
100 printf(_("warning: couldn't set environment variable 'DISPLAY'\n"));
104 // find the availability of X extensions we like to use
106 _shape
= XShapeQueryExtension(display
, &_shape_event_basep
, &junk
);
110 _xinerama
= XineramaQueryExtension(display
, &_xinerama_event_basep
, &junk
);
113 // get lock masks that are defined by the display (not constant)
114 XModifierKeymap
*modmap
;
115 unsigned int NumLockMask
= 0, ScrollLockMask
= 0;
117 modmap
= XGetModifierMapping(display
);
118 if (modmap
&& modmap
->max_keypermod
> 0) {
119 const int mask_table
[] = {
120 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
121 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
123 const size_t size
= (sizeof(mask_table
) / sizeof(mask_table
[0])) *
124 modmap
->max_keypermod
;
125 // get the values of the keyboard lock modifiers
126 // Note: Caps lock is not retrieved the same way as Scroll and Num lock
127 // since it doesn't need to be.
128 const KeyCode num_lock
= XKeysymToKeycode(display
, XK_Num_Lock
);
129 const KeyCode scroll_lock
= XKeysymToKeycode(display
, XK_Scroll_Lock
);
131 for (size_t cnt
= 0; cnt
< size
; ++cnt
) {
132 if (! modmap
->modifiermap
[cnt
]) continue;
134 if (num_lock
== modmap
->modifiermap
[cnt
])
135 NumLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
136 if (scroll_lock
== modmap
->modifiermap
[cnt
])
137 ScrollLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
141 if (modmap
) XFreeModifiermap(modmap
);
144 _mask_list
[1] = LockMask
;
145 _mask_list
[2] = NumLockMask
;
146 _mask_list
[3] = LockMask
| NumLockMask
;
147 _mask_list
[4] = ScrollLockMask
;
148 _mask_list
[5] = ScrollLockMask
| LockMask
;
149 _mask_list
[6] = ScrollLockMask
| NumLockMask
;
150 _mask_list
[7] = ScrollLockMask
| LockMask
| NumLockMask
;
152 // Get information on all the screens which are available.
153 _screenInfoList
.reserve(ScreenCount(display
));
154 for (int i
= 0; i
< ScreenCount(display
); ++i
)
155 _screenInfoList
.push_back(ScreenInfo(i
));
157 _gccache
= new BGCCache(_screenInfoList
.size());
161 void OBDisplay::destroy()
164 XCloseDisplay(display
);
168 const ScreenInfo
* OBDisplay::screenInfo(int snum
) {
170 assert(snum
< static_cast<int>(_screenInfoList
.size()));
171 return &_screenInfoList
[snum
];
183 * Grabs a button, but also grabs the button in every possible combination
184 * with the keyboard lock keys, so that they do not cancel out the event.
186 * if allow_scroll_lock is true then only the top half of the lock mask
187 * table is used and scroll lock is ignored. This value defaults to false.
189 void OBDisplay::grabButton(unsigned int button
, unsigned int modifiers
,
190 Window grab_window
, bool owner_events
,
191 unsigned int event_mask
, int pointer_mode
,
192 int keyboard_mode
, Window confine_to
,
193 Cursor cursor
, bool allow_scroll_lock
) {
194 unsigned int length
= (allow_scroll_lock
) ? 8 / 2:
196 for (size_t cnt
= 0; cnt
< length
; ++cnt
)
197 XGrabButton(otk::OBDisplay::display
, button
, modifiers
| _mask_list
[cnt
],
198 grab_window
, owner_events
, event_mask
, pointer_mode
,
199 keyboard_mode
, confine_to
, cursor
);
204 * Releases the grab on a button, and ungrabs all possible combinations of the
205 * keyboard lock keys.
207 void OBDisplay::ungrabButton(unsigned int button
, unsigned int modifiers
,
208 Window grab_window
) {
209 for (size_t cnt
= 0; cnt
< 8; ++cnt
)
210 XUngrabButton(otk::OBDisplay::display
, button
, modifiers
| _mask_list
[cnt
],
This page took 0.053034 seconds and 4 git commands to generate.