Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* GIMP RGBA C-Source image dump (MacButton_Normal.c) */
- #include <xcb/xcb.h>
- #include <xcb/xcb_atom.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- static const struct {
- unsigned int width;
- unsigned int height;
- unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
- unsigned char pixel_data[1 * 35 * 4 + 1];
- } macBtnNormal = {
- 1, 35, 4,
- "{{{\377\204\204\204\377\212\212\212\377\210\210\210\377\204\204\204\377\201"
- "\201\201\377\177\177\177\377|||\377zzz\377xxx\377www\377vvv\377ttt\377ss"
- "s\377sss\377rrr\377ooo\377```\377^^^\377___\377```\377```\377aaa\377bbb\377"
- "ccc\377eee\377ggg\377iii\377lll\377nnn\377ppp\377uuu\377rrr\377ddd\377\300"
- "\300\300\377",
- };
- static const struct {
- unsigned int width;
- unsigned int height;
- unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
- unsigned char pixel_data[1 * 35 * 4 + 1];
- } macBtnHilite = {
- 1, 35, 4,
- "\232\\u\377\245c}\377\253i\203\377\252f\201\377\245c}\377\242`z\377\240^"
- "x\377\233]v\377\230\\t\377\225[r\377\224Zq\377\222Zp\377\217Yo\377\216Xn"
- "\377\216Xn\377\214Xm\377\211Uj\377xH[\377vFY\377wGZ\377xH[\377xH[\377yI\\"
- "\377{I]\377{K^\377~L`\377\200Nb\377\202Pc\377\205Sf\377\207Uh\377\212Vk\377"
- "\221Yo\377\214Xm\377}K_\377\331\247\273\377",
- };
- static uint8_t* btnNormalData = (uint8_t*)macBtnNormal.pixel_data;
- static uint8_t* btnHiliteData = (uint8_t*)macBtnHilite.pixel_data;
- xcb_connection_t* conn;
- xcb_window_t win;
- xcb_screen_t* screen;
- int main(int argc, const char** argv)
- {
- xcb_generic_event_t* evt;
- xcb_gcontext_t gc;
- xcb_pixmap_t pm, pm2;
- xcb_window_t btn_test;
- uint32_t i;
- xcb_generic_error_t* err;
- xcb_void_cookie_t cookie;
- uint32_t values[] = {
- 0xc0c0c0,
- XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS |
- XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS |
- XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_ENTER_WINDOW |
- XCB_EVENT_MASK_LEAVE_WINDOW,
- 0, 0, 0, 0
- };
- if (((conn = xcb_connect(NULL, NULL)) == NULL) || (xcb_connection_has_error(conn))) {
- fprintf(stderr, "Could not connect X Server\n");
- return -1;
- }
- screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
- win = xcb_generate_id(conn);
- pm = xcb_generate_id(conn);
- pm2 = xcb_generate_id(conn);
- btn_test = xcb_generate_id(conn);
- gc = xcb_generate_id(conn);
- xcb_create_window(conn, 0, win,
- screen->root,
- 100, 100, 500, 180,
- 1, XCB_WINDOW_CLASS_INPUT_OUTPUT,
- screen->root_visual,
- XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
- values);
- xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win,
- WM_NAME, STRING, 8, strlen("XCB Button Test"),
- "XCB Button Test");
- xcb_create_gc(conn, gc, win, 0, NULL);
- xcb_create_pixmap(conn, screen->root_depth,
- pm, win, 1, 35);
- xcb_create_pixmap(conn, screen->root_depth, pm2, win, 1, 35);
- cookie = xcb_put_image_checked(conn, 2, pm,
- gc, 1, 35, 0, 0, 0,
- screen->root_depth,
- 35*4, btnNormalData);
- if (err = xcb_request_check(conn, cookie)) {
- fprintf(stderr, "Unable to put image into drawable %u\nError %d\n",
- pm, err->error_code);
- free(err);
- return -1;
- }
- cookie = xcb_put_image_checked(conn, 2, pm2,
- gc, 1, 35, 0, 0, 0,
- screen->root_depth,
- 35*4, btnHiliteData);
- if (err = xcb_request_check(conn, cookie)) {
- fprintf(stderr, "Unable to put image into drawable %u\nError %d\n",
- pm2, err->error_code);
- free(err);
- return -1;
- }
- values[0] = pm;
- xcb_create_window(conn, 0, btn_test,
- win, 500-90, 180-55, 70, 35,
- 1, XCB_WINDOW_CLASS_INPUT_OUTPUT,
- screen->root_visual,
- XCB_CW_BACK_PIXMAP | XCB_CW_EVENT_MASK,
- values);
- xcb_map_subwindows(conn, win);
- xcb_map_window(conn, win);
- xcb_flush(conn);
- while (evt = xcb_wait_for_event(conn)) {
- int ntype = evt->response_type & ~0x80;
- if (ntype == XCB_BUTTON_PRESS) {
- xcb_button_press_event_t* event = (xcb_button_press_event_t*)evt;
- if (event->event == btn_test)
- break;
- } else if (ntype == XCB_ENTER_NOTIFY) {
- xcb_enter_notify_event_t* event = (xcb_enter_notify_event_t*)evt;
- uint32_t vals[] = { pm2 };
- if (event->event == btn_test) {
- /* change the BACK_PIXMAP property into using pm2... */
- fprintf(stdout, "Event->window == btn_test, change the image\n");
- xcb_change_window_attributes(conn, btn_test, XCB_CW_BACK_PIXMAP, vals);
- xcb_clear_area(conn, 1, btn_test, 0, 0, 70, 35);
- xcb_flush(conn);
- }
- } else if (ntype == XCB_LEAVE_NOTIFY) {
- xcb_leave_notify_event_t* event = (xcb_leave_notify_event_t*)evt;
- uint32_t vals[] = { pm };
- if (event->event == btn_test) {
- /* change the BACK_PIXMAP property into using pm2... */
- fprintf(stdout, "Event->window == btn_test, change the image\n");
- xcb_change_window_attributes(conn, btn_test, XCB_CW_BACK_PIXMAP, vals);
- xcb_clear_area(conn, 1, btn_test, 0, 0, 70, 35);
- xcb_flush(conn);
- }
- }
- free(evt);
- }
- xcb_destroy_window(conn, win);
- xcb_disconnect(conn);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement