-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.c
More file actions
83 lines (71 loc) · 1.91 KB
/
screen.c
File metadata and controls
83 lines (71 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdlib.h>
#include <xcb/xcb.h>
#ifdef XINERAMA
#include <xcb/xinerama.h>
#endif
#include "screen.h"
#ifdef XINERAMA
// thanks awesome
int get_xinerama_screen_geom(struct x_context *xc, struct geom *geom,
uint16_t x, uint16_t y)
{
/* check for extension before checking for xinerama */
int xinerama_is_active = 0;
if(xcb_get_extension_data(xc->conn, &xcb_xinerama_id)->present) {
xcb_xinerama_is_active_reply_t *xia;
xia = xcb_xinerama_is_active_reply(xc->conn,
xcb_xinerama_is_active(xc->conn), NULL);
xinerama_is_active = xia->state;
free(xia);
}
if(!xinerama_is_active)
return 1;
xcb_xinerama_query_screens_reply_t *xsq;
xcb_xinerama_screen_info_t *xsi;
xsq = xcb_xinerama_query_screens_reply(xc->conn,
xcb_xinerama_query_screens_unchecked(xc->conn), NULL);
xsi = xcb_xinerama_query_screens_screen_info(xsq);
int screen_len = xcb_xinerama_query_screens_screen_info_length(xsq);
int i;
for(i = 0; i < screen_len; i++) {
if (x >= xsi[i].x_org &&
x <= xsi[i].x_org + xsi[i].width &&
y >= xsi[i].y_org &&
y <= xsi[i].y_org + xsi[i].height) {
geom->x = xsi[i].x_org;
geom->y = xsi[i].y_org;
geom->w = xsi[i].width;
geom->h = xsi[i].height;
free(xsq);
return 0;
}
}
free(xsq);
return 1;
}
#endif
int get_screen_geom(struct x_context *xc, struct geom *geom)
{
if (!geom)
return 1;
#ifdef XINERAMA
/* get mouse coord */
xcb_query_pointer_cookie_t query_ptr_c;
xcb_query_pointer_reply_t *query_ptr_r;
query_ptr_c = xcb_query_pointer_unchecked(xc->conn, xc->screen->root);
query_ptr_r = xcb_query_pointer_reply(xc->conn, query_ptr_c, NULL);
if(query_ptr_r) {
uint16_t x, y;
x = query_ptr_r->win_x;
y = query_ptr_r->win_y;
free(query_ptr_r);
if (!get_xinerama_screen_geom(xc, geom, x, y))
return 0;
}
#endif
/* fallback to X */
geom->x = geom->y = 0;
geom->w = xc->screen->width_in_pixels;
geom->h = xc->screen->height_in_pixels;
return 0;
}