1 #include "bcdisplayinfo.h"
10 #define TEST_SIZE2 164
11 #define TEST_SIZE3 196
12 int BC_DisplayInfo::top_border = -1;
13 int BC_DisplayInfo::left_border = -1;
14 int BC_DisplayInfo::bottom_border = -1;
15 int BC_DisplayInfo::right_border = -1;
16 int BC_DisplayInfo::auto_reposition_x = -1;
17 int BC_DisplayInfo::auto_reposition_y = -1;
20 BC_DisplayInfo::BC_DisplayInfo(char *display_name, int show_error)
22 init_window(display_name, show_error);
25 BC_DisplayInfo::~BC_DisplayInfo()
27 XCloseDisplay(display);
31 void BC_DisplayInfo::parse_geometry(char *geom, int *x, int *y, int *width, int *height)
33 XParseGeometry(geom, x, y, (unsigned int*)width, (unsigned int*)height);
36 void BC_DisplayInfo::test_window(int &x_out,
43 unsigned long mask = CWEventMask | CWWinGravity;
44 XSetWindowAttributes attr;
45 XSizeHints size_hints;
47 //printf("BC_DisplayInfo::test_window 1\n");
52 attr.event_mask = StructureNotifyMask;
53 attr.win_gravity = SouthEastGravity;
54 Window win = XCreateWindow(display,
66 XGetNormalHints(display, win, &size_hints);
67 size_hints.flags = PPosition | PSize;
70 size_hints.width = TEST_SIZE;
71 size_hints.height = TEST_SIZE;
72 XSetStandardProperties(display,
81 XMapWindow(display, win);
84 XMoveResizeWindow(display,
93 XResizeWindow(display,
107 XNextEvent(display, &event);
108 //printf("BC_DisplayInfo::test_window 1 event=%d %d\n", event.type, XPending(display));
109 if(event.type == ConfigureNotify && event.xany.window == win)
111 // Get creation repositioning
112 if(last_w != event.xconfigure.width || last_h != event.xconfigure.height)
115 last_w = event.xconfigure.width;
116 last_h = event.xconfigure.height;
121 x_out = MAX(event.xconfigure.x + event.xconfigure.border_width - x_in, x_out);
122 y_out = MAX(event.xconfigure.y + event.xconfigure.border_width - y_in, y_out);
126 // Get moveresize repositioning
128 x_out2 = MAX(event.xconfigure.x + event.xconfigure.border_width - x_in, x_out2);
129 y_out2 = MAX(event.xconfigure.y + event.xconfigure.border_width - y_in, y_out2);
131 // printf("BC_DisplayInfo::test_window 2 state=%d x_out=%d y_out=%d x_in=%d y_in=%d w=%d h=%d\n",
133 // event.xconfigure.x + event.xconfigure.border_width,
134 // event.xconfigure.y + event.xconfigure.border_width,
137 // event.xconfigure.width,
138 // event.xconfigure.height);
142 XDestroyWindow(display, win);
146 x_out = MAX(0, x_out);
147 y_out = MAX(0, y_out);
148 x_out = MIN(x_out, 30);
149 y_out = MIN(y_out, 30);
150 //printf("BC_DisplayInfo::test_window 2\n");
153 void BC_DisplayInfo::init_borders()
158 test_window(left_border,
164 right_border = left_border;
165 bottom_border = left_border;
166 // printf("BC_DisplayInfo::init_borders border=%d %d auto=%d %d\n",
169 // auto_reposition_x,
170 // auto_reposition_y);
175 int BC_DisplayInfo::get_top_border()
181 int BC_DisplayInfo::get_left_border()
187 int BC_DisplayInfo::get_right_border()
193 int BC_DisplayInfo::get_bottom_border()
196 return bottom_border;
199 void BC_DisplayInfo::init_window(char *display_name, int show_error)
201 if(display_name && display_name[0] == 0) display_name = NULL;
203 // This function must be the first Xlib
204 // function a multi-threaded program calls
207 if((display = XOpenDisplay(display_name)) == NULL)
211 printf("BC_DisplayInfo::init_window: cannot connect to X server.\n");
212 if(getenv("DISPLAY") == NULL)
213 printf("'DISPLAY' environment variable not set.\n");
219 screen = DefaultScreen(display);
220 rootwin = RootWindow(display, screen);
221 vis = DefaultVisual(display, screen);
222 default_depth = DefaultDepth(display, screen);
226 int BC_DisplayInfo::get_root_w()
228 Screen *screen_ptr = XDefaultScreenOfDisplay(display);
229 return WidthOfScreen(screen_ptr);
232 int BC_DisplayInfo::get_root_h()
234 Screen *screen_ptr = XDefaultScreenOfDisplay(display);
235 return HeightOfScreen(screen_ptr);
238 int BC_DisplayInfo::get_abs_cursor_x()
240 int abs_x, abs_y, win_x, win_y;
241 unsigned int temp_mask;
244 XQueryPointer(display,
256 int BC_DisplayInfo::get_abs_cursor_y()
258 int abs_x, abs_y, win_x, win_y;
259 unsigned int temp_mask;
262 XQueryPointer(display,
276 // c-file-style: "linux"