Annotation of /mcore-src/trunk/mcore-tools/src/xinfo.c
Parent Directory | Revision Log
Revision 2101 -
(hide annotations)
(download)
Fri Sep 27 10:34:07 2013 UTC (11 years ago) by niro
File MIME type: text/plain
File size: 1052 byte(s)
Fri Sep 27 10:34:07 2013 UTC (11 years ago) by niro
File MIME type: text/plain
File size: 1052 byte(s)
-serveral fixes: check for display, fixed return values and fixed a typo
1 | niro | 2101 | // original code grabbed from: |
2 | niro | 2100 | // http://surfingtroves.blogspot.de/2011/01/how-to-get-screen-resolution-in-linux-c.html |
3 | |||
4 | // ----------------------------------------------------------- | ||
5 | // Purpose : simply retrieve current X windows information | ||
6 | // ----------------------------------------------------------- | ||
7 | #define XLIB_ILLEGAL_ACCESS | ||
8 | #include <X11/Xlib.h> | ||
9 | #include <stdio.h> | ||
10 | |||
11 | int main() | ||
12 | { | ||
13 | |||
14 | Display* pdsp = XOpenDisplay(NULL); | ||
15 | niro | 2101 | if (! pdsp) { |
16 | printf("No display found!\n"); | ||
17 | return 1; | ||
18 | } | ||
19 | niro | 2100 | Window wid = DefaultRootWindow(pdsp); |
20 | |||
21 | Screen* pwnd = DefaultScreenOfDisplay(pdsp); | ||
22 | int sid = DefaultScreen(pdsp); | ||
23 | niro | 2101 | |
24 | niro | 2100 | XWindowAttributes xwAttr; |
25 | XGetWindowAttributes(pdsp,wid,&xwAttr); | ||
26 | |||
27 | /* | ||
28 | printf(" name : %s\n vendor : %s\n", pdsp->display_name, pdsp->vendor); | ||
29 | printf(" pos : (%d, %d), width = %d, height = %d \n", | ||
30 | xwAttr.x, xwAttr.y, xwAttr.width, xwAttr.height); | ||
31 | */ | ||
32 | |||
33 | niro | 2101 | printf("xorg_width=%d\n", xwAttr.width); |
34 | niro | 2100 | printf("xorg_height=%d\n", xwAttr.height); |
35 | |||
36 | XCloseDisplay( pdsp ); | ||
37 | niro | 2101 | |
38 | return 0; | ||
39 | niro | 2100 | } |
40 | |||
41 | /* gcc -o $@ $< -lX11 */ | ||
42 | /* set ts=4 sts=4 tw=100 sw=4 */ |