]>
Dogcows Code - chaz/openbox/blob - tests/icons.c
4 #include <X11/cursorfont.h>
9 Window
findClient(Display
*d
, Window win
)
13 Atom state
= XInternAtom(d
, "WM_STATE", True
);
16 unsigned long ret_items
, ret_bytesleft
;
17 unsigned long *prop_return
;
19 XQueryTree(d
, win
, &r
, &r
, &children
, &n
);
20 for (i
= 0; i
< n
; ++i
) {
21 Window w
= findClient(d
, children
[i
]);
26 XGetWindowProperty(d
, win
, state
, 0, 1,
27 False
, state
, &ret_type
, &ret_format
,
28 &ret_items
, &ret_bytesleft
,
29 (unsigned char**) &prop_return
);
30 if (ret_type
== None
|| ret_items
< 1)
32 return win
; // found it!
35 int main(int argc
, char **argv
)
37 Display
*d
= XOpenDisplay(NULL
);
38 int s
= DefaultScreen(d
);
39 Atom net_wm_icon
= XInternAtom(d
, "_NET_WM_ICON", True
);
41 unsigned int winw
= 0, winh
= 0;
43 unsigned long ret_items
, ret_bytesleft
;
44 const int MAX_IMAGES
= 10;
45 unsigned long *prop_return
[MAX_IMAGES
];
46 XImage
*i
[MAX_IMAGES
];
48 unsigned int image
= 0;
49 unsigned int j
; // loop counter
51 printf("Click on a window with an icon...\n");
53 //int id = strtol(argv[1], NULL, 16);
54 XUngrabPointer(d
, CurrentTime
);
56 Cursor cur
= XCreateFontCursor(d
, XC_crosshair
);
57 XGrabPointer(d
, RootWindow(d
, s
), False
, ButtonPressMask
, GrabModeAsync
,
58 GrabModeAsync
, None
, cur
, CurrentTime
);
62 if (ev
.type
== ButtonPress
) {
63 XUngrabPointer(d
, CurrentTime
);
64 id
= findClient(d
, ev
.xbutton
.subwindow
);
69 printf("Using window 0x%lx\n", id
);
74 XGetWindowProperty(d
, id
, net_wm_icon
, offset
++, 1,
75 False
, XA_CARDINAL
, &ret_type
, &ret_format
,
76 &ret_items
, &ret_bytesleft
,
77 (unsigned char**) &prop_return
[image
]);
78 if (ret_type
== None
|| ret_items
< 1) {
79 printf("No icon found\n");
82 w
= prop_return
[image
][0];
83 XFree(prop_return
[image
]);
85 XGetWindowProperty(d
, id
, net_wm_icon
, offset
++, 1,
86 False
, XA_CARDINAL
, &ret_type
, &ret_format
,
87 &ret_items
, &ret_bytesleft
,
88 (unsigned char**) &prop_return
[image
]);
89 if (ret_type
== None
|| ret_items
< 1) {
90 printf("Failed to get height\n");
93 h
= prop_return
[image
][0];
94 XFree(prop_return
[image
]);
96 XGetWindowProperty(d
, id
, net_wm_icon
, offset
, w
*h
,
97 False
, XA_CARDINAL
, &ret_type
, &ret_format
,
98 &ret_items
, &ret_bytesleft
,
99 (unsigned char**) &prop_return
[image
]);
100 if (ret_type
== None
|| ret_items
< w
*h
) {
101 printf("Failed to get image data\n");
106 printf("Found icon with size %dx%d\n", w
, h
);
108 i
[image
] = XCreateImage(d
, DefaultVisual(d
, s
), DefaultDepth(d
, s
),
109 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
111 i
[image
]->byte_order
= LSBFirst
;
112 i
[image
]->data
= (char*)prop_return
[image
];
113 for (j
= 0; j
< w
*h
; j
++) {
114 unsigned char alpha
= (unsigned char)i
[image
]->data
[j
*4+3];
115 unsigned char r
= (unsigned char) i
[image
]->data
[j
*4+0];
116 unsigned char g
= (unsigned char) i
[image
]->data
[j
*4+1];
117 unsigned char b
= (unsigned char) i
[image
]->data
[j
*4+2];
120 unsigned char bgr
= 0;
121 unsigned char bgg
= 0;
122 unsigned char bgb
= 0;
124 r
= bgr
+ (r
- bgr
) * alpha
/ 256;
125 g
= bgg
+ (g
- bgg
) * alpha
/ 256;
126 b
= bgb
+ (b
- bgb
) * alpha
/ 256;
128 i
[image
]->data
[j
*4+0] = (char) r
;
129 i
[image
]->data
[j
*4+1] = (char) g
;
130 i
[image
]->data
[j
*4+2] = (char) b
;
134 if (h
> winh
) winh
= h
;
137 } while (ret_bytesleft
> 0 && image
< MAX_IMAGES
);
139 Window win
= XCreateSimpleWindow(d
, RootWindow(d
, s
), 0, 0, winw
, winh
,
144 Pixmap p
= XCreatePixmap(d
, win
, winw
, winh
, DefaultDepth(d
, s
));
145 XFillRectangle(d
, p
, DefaultGC(d
, s
), 0, 0, winw
, winh
);
148 for (j
= 0; j
< image
; ++j
) {
149 XPutImage(d
, p
, DefaultGC(d
, s
), i
[j
], 0, 0, x
, 0,
150 i
[j
]->width
, i
[j
]->height
);
155 XSetWindowBackgroundPixmap(d
, win
, p
);
156 XClearWindow(d
, win
);
This page took 0.040381 seconds and 4 git commands to generate.