Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /* GIMP RGBA C-Source image dump (MacButton_Normal.c) */
  2.  
  3. #include <xcb/xcb.h>
  4. #include <xcb/xcb_atom.h>
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10.  
  11. static const struct {
  12.   unsigned int   width;
  13.   unsigned int   height;
  14.   unsigned int   bytes_per_pixel; /* 3:RGB, 4:RGBA */
  15.   unsigned char  pixel_data[1 * 35 * 4 + 1];
  16. } macBtnNormal = {
  17.   1, 35, 4,
  18.   "{{{\377\204\204\204\377\212\212\212\377\210\210\210\377\204\204\204\377\201"
  19.   "\201\201\377\177\177\177\377|||\377zzz\377xxx\377www\377vvv\377ttt\377ss"
  20.   "s\377sss\377rrr\377ooo\377```\377^^^\377___\377```\377```\377aaa\377bbb\377"
  21.   "ccc\377eee\377ggg\377iii\377lll\377nnn\377ppp\377uuu\377rrr\377ddd\377\300"
  22.   "\300\300\377",
  23. };
  24.  
  25. static const struct {
  26.     unsigned int     width;
  27.     unsigned int     height;
  28.     unsigned int     bytes_per_pixel; /* 3:RGB, 4:RGBA */
  29.     unsigned char    pixel_data[1 * 35 * 4 + 1];
  30. } macBtnHilite = {
  31.     1, 35, 4,
  32.     "\232\\u\377\245c}\377\253i\203\377\252f\201\377\245c}\377\242`z\377\240^"
  33.     "x\377\233]v\377\230\\t\377\225[r\377\224Zq\377\222Zp\377\217Yo\377\216Xn"
  34.     "\377\216Xn\377\214Xm\377\211Uj\377xH[\377vFY\377wGZ\377xH[\377xH[\377yI\\"
  35.     "\377{I]\377{K^\377~L`\377\200Nb\377\202Pc\377\205Sf\377\207Uh\377\212Vk\377"
  36.     "\221Yo\377\214Xm\377}K_\377\331\247\273\377",
  37. };
  38.  
  39. static uint8_t* btnNormalData = (uint8_t*)macBtnNormal.pixel_data;
  40. static uint8_t* btnHiliteData = (uint8_t*)macBtnHilite.pixel_data;
  41.  
  42. xcb_connection_t* conn;
  43. xcb_window_t win;
  44. xcb_screen_t* screen;
  45.  
  46. int main(int argc, const char** argv)
  47. {
  48.     xcb_generic_event_t* evt;
  49.     xcb_gcontext_t gc;
  50.     xcb_pixmap_t pm, pm2;  
  51.     xcb_window_t btn_test;
  52.     uint32_t i;
  53.     xcb_generic_error_t* err;
  54.     xcb_void_cookie_t cookie;
  55.    
  56.     uint32_t values[] = {
  57.         0xc0c0c0,
  58.         XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS |
  59.         XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS |
  60.         XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_ENTER_WINDOW |
  61.         XCB_EVENT_MASK_LEAVE_WINDOW,
  62.         0, 0, 0, 0
  63.     };
  64.    
  65.     if (((conn = xcb_connect(NULL, NULL)) == NULL) || (xcb_connection_has_error(conn))) {
  66.         fprintf(stderr, "Could not connect X Server\n");
  67.         return -1;
  68.     }
  69.    
  70.     screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
  71.    
  72.     win = xcb_generate_id(conn);
  73.     pm = xcb_generate_id(conn);
  74.     pm2 = xcb_generate_id(conn);
  75.     btn_test = xcb_generate_id(conn);
  76.     gc = xcb_generate_id(conn);
  77.    
  78.     xcb_create_window(conn, 0, win,
  79.                       screen->root,
  80.                       100, 100, 500, 180,
  81.                       1, XCB_WINDOW_CLASS_INPUT_OUTPUT,
  82.                       screen->root_visual,
  83.                       XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
  84.                       values);
  85.     xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win,
  86.                         WM_NAME, STRING, 8, strlen("XCB Button Test"),
  87.                         "XCB Button Test");
  88.    
  89.     xcb_create_gc(conn, gc, win, 0, NULL);
  90.     xcb_create_pixmap(conn, screen->root_depth,
  91.                       pm, win, 1, 35);
  92.     xcb_create_pixmap(conn, screen->root_depth, pm2, win, 1, 35);
  93.    
  94.     cookie = xcb_put_image_checked(conn, 2, pm,
  95.                                    gc, 1, 35, 0, 0, 0,
  96.                                    screen->root_depth,
  97.                                    35*4, btnNormalData);
  98.     if (err = xcb_request_check(conn, cookie)) {
  99.         fprintf(stderr, "Unable to put image into drawable %u\nError %d\n",
  100.                 pm, err->error_code);
  101.         free(err);
  102.         return -1;
  103.     }
  104.    
  105.     cookie = xcb_put_image_checked(conn, 2, pm2,
  106.                                    gc, 1, 35, 0, 0, 0,
  107.                                    screen->root_depth,
  108.                                    35*4, btnHiliteData);
  109.     if (err = xcb_request_check(conn, cookie)) {
  110.         fprintf(stderr, "Unable to put image into drawable %u\nError %d\n",
  111.                 pm2, err->error_code);
  112.         free(err);
  113.         return -1;
  114.     }
  115.    
  116.     values[0] = pm;
  117.     xcb_create_window(conn, 0, btn_test,
  118.                       win, 500-90, 180-55, 70, 35,
  119.                       1, XCB_WINDOW_CLASS_INPUT_OUTPUT,
  120.                       screen->root_visual,
  121.                       XCB_CW_BACK_PIXMAP | XCB_CW_EVENT_MASK,
  122.                       values);
  123.     xcb_map_subwindows(conn, win);
  124.     xcb_map_window(conn, win);
  125.     xcb_flush(conn);
  126.    
  127.     while (evt = xcb_wait_for_event(conn)) {
  128.         int ntype = evt->response_type & ~0x80;
  129.         if (ntype == XCB_BUTTON_PRESS) {
  130.             xcb_button_press_event_t* event = (xcb_button_press_event_t*)evt;
  131.             if (event->event == btn_test)
  132.                 break;
  133.         } else if (ntype == XCB_ENTER_NOTIFY) {
  134.             xcb_enter_notify_event_t* event = (xcb_enter_notify_event_t*)evt;
  135.             uint32_t vals[] = { pm2 };
  136.             if (event->event == btn_test) {
  137.                 /* change the BACK_PIXMAP property into using pm2... */
  138.                 fprintf(stdout, "Event->window == btn_test, change the image\n");
  139.                 xcb_change_window_attributes(conn, btn_test, XCB_CW_BACK_PIXMAP, vals);
  140.                 xcb_clear_area(conn, 1, btn_test, 0, 0, 70, 35);
  141.                 xcb_flush(conn);
  142.             }
  143.         } else if (ntype == XCB_LEAVE_NOTIFY) {
  144.             xcb_leave_notify_event_t* event = (xcb_leave_notify_event_t*)evt;
  145.             uint32_t vals[] = { pm };
  146.             if (event->event == btn_test) {
  147.                 /* change the BACK_PIXMAP property into using pm2... */
  148.                 fprintf(stdout, "Event->window == btn_test, change the image\n");
  149.                 xcb_change_window_attributes(conn, btn_test, XCB_CW_BACK_PIXMAP, vals);
  150.                 xcb_clear_area(conn, 1, btn_test, 0, 0, 70, 35);
  151.                 xcb_flush(conn);
  152.             }
  153.         }
  154.         free(evt);
  155.     }
  156.    
  157.     xcb_destroy_window(conn, win);
  158.     xcb_disconnect(conn);
  159.     return 0;
  160. }
  161.  
  162.