]>
Dogcows Code - chaz/openbox/blob - otk/display.cc
9e6685b9864d7fb1a5eb7cea0e0adf061d50930d
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
8 #include "screeninfo.hh"
12 #include <X11/keysym.h>
16 #endif // HAVE_STDIO_H
20 #endif // HAVE_STDLIB_H
24 #endif // HAVE_SIGNAL_H
28 #endif // HAVE_FCNTL_H
31 # include <sys/types.h>
33 #endif // HAVE_UNISTD_H
36 #define _(str) gettext(str)
42 Display
*display
= (Display
*) 0;
45 int OBDisplay::xerrorHandler(Display
*d
, XErrorEvent
*e
)
50 XGetErrorText(d
, e
->error_code
, errtxt
, 128);
51 printf("X Error: %s\n", errtxt
);
61 void OBDisplay::initialize(char *name
)
67 if (!(display
= XOpenDisplay(name
))) {
68 printf(_("Unable to open connection to the X server. Please set the \n\
69 DISPLAY environment variable approriately, or use the '-display' command \n\
70 line argument.\n\n"));
73 if (fcntl(ConnectionNumber(display
), F_SETFD
, 1) == -1) {
74 printf(_("Couldn't mark display connection as close-on-exec.\n\n"));
78 // set our error handler for X errors
79 XSetErrorHandler(xerrorHandler
);
81 // set the DISPLAY environment variable for any lauched children, to the
82 // display we're using, so they open in the right place.
83 // XXX rm -> std::string dtmp = "DISPLAY=" + DisplayString(display);
84 if (putenv(const_cast<char*>((std::string("DISPLAY=") +
85 DisplayString(display
)).c_str()))) {
86 printf(_("warning: couldn't set environment variable 'DISPLAY'\n"));
90 // find the availability of X extensions we like to use
92 _shape
= XShapeQueryExtension(display
, &_shape_event_basep
, &junk
);
98 _xinerama
= XineramaQueryExtension(display
, &_xinerama_event_basep
, &junk
);
103 // get lock masks that are defined by the display (not constant)
104 XModifierKeymap
*modmap
;
105 unsigned int NumLockMask
= 0, ScrollLockMask
= 0;
107 modmap
= XGetModifierMapping(display
);
108 if (modmap
&& modmap
->max_keypermod
> 0) {
109 const int mask_table
[] = {
110 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
111 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
113 const size_t size
= (sizeof(mask_table
) / sizeof(mask_table
[0])) *
114 modmap
->max_keypermod
;
115 // get the values of the keyboard lock modifiers
116 // Note: Caps lock is not retrieved the same way as Scroll and Num lock
117 // since it doesn't need to be.
118 const KeyCode num_lock
= XKeysymToKeycode(display
, XK_Num_Lock
);
119 const KeyCode scroll_lock
= XKeysymToKeycode(display
, XK_Scroll_Lock
);
121 for (size_t cnt
= 0; cnt
< size
; ++cnt
) {
122 if (! modmap
->modifiermap
[cnt
]) continue;
124 if (num_lock
== modmap
->modifiermap
[cnt
])
125 NumLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
126 if (scroll_lock
== modmap
->modifiermap
[cnt
])
127 ScrollLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
131 if (modmap
) XFreeModifiermap(modmap
);
134 _mask_list
[1] = LockMask
;
135 _mask_list
[2] = NumLockMask
;
136 _mask_list
[3] = LockMask
| NumLockMask
;
137 _mask_list
[4] = ScrollLockMask
;
138 _mask_list
[5] = ScrollLockMask
| LockMask
;
139 _mask_list
[6] = ScrollLockMask
| NumLockMask
;
140 _mask_list
[7] = ScrollLockMask
| LockMask
| NumLockMask
;
142 // Get information on all the screens which are available.
143 _screenInfoList
.reserve(ScreenCount(display
));
144 for (int i
= 0; i
< ScreenCount(display
); ++i
)
145 _screenInfoList
.push_back(ScreenInfo(i
));
147 _gccache
= new BGCCache(_screenInfoList
.size());
151 void OBDisplay::destroy()
154 XCloseDisplay(display
);
This page took 0.037938 seconds and 4 git commands to generate.