void update_bar_ws(unsigned int idx) { xcb_rectangle_t rect; uint32_t vals[2]; char text[3]; int len; /* colors */ vals[0] = nil_.color.bar_fg; if (idx == nil_.ws_idx) { /* focused workspace */ vals[1] = nil_.color.bar_sel; } else if (nil_.ws[idx].first) { /* has a client */ vals[1] = nil_.color.bar_occ; } else { vals[1] = nil_.color.bar_bg; } xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND, &vals[1]); rect.width = bar_.box[BAR_WS].w / cfg_.num_workspaces; rect.height = bar_.h; rect.x = bar_.box[BAR_WS].x + rect.width * idx; rect.y = 0; xcb_poly_fill_rectangle(nil_.con, bar_.win, bar_.gc, 1, &rect); /* text */ xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, vals); len = snprintf(text, sizeof(text), "%u", idx + 1); rect.x += CENTER_H_(rect.width, cal_text_width(text, len)); rect.y += CENTER_V_(rect.height); xcb_image_text_8(nil_.con, len, bar_.win, bar_.gc, rect.x, rect.y, text); }
void VlcWindowlessXCB::drawBackground(xcb_drawable_t drawable) { /* Obtain the background color */ xcb_colormap_t colormap = m_screen->default_colormap; unsigned r = 0, g = 0, b = 0; HTMLColor2RGB(get_options().get_bg_color().c_str(), &r, &g, &b); xcb_alloc_color_reply_t *reply = xcb_alloc_color_reply(m_conn, xcb_alloc_color(m_conn, colormap, (uint16_t) r << 8, (uint16_t) g << 8, (uint16_t) b << 8), NULL); uint32_t colorpixel = reply->pixel; free(reply); /* Prepare to fill the background */ xcb_gcontext_t background = xcb_generate_id(m_conn); uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; uint32_t values[2] = {colorpixel, 0}; xcb_create_gc(m_conn, background, drawable, mask, values); xcb_rectangle_t rect; rect.x = 0; rect.y = 0; rect.width = npwindow.width; rect.height = npwindow.height; /* Fill the background */ xcb_poly_fill_rectangle(m_conn, drawable, background, 1, &rect); xcb_free_gc(m_conn, background); }
void xcbosd_clear(xcbosd *osd) { int i; lprintf("clear (state:%d)\n", osd->clean ); if( osd->clean != WIPED ) switch (osd->mode) { case XCBOSD_SHAPED: { xcb_rectangle_t rectangle = { 0, 0, osd->width, osd->height }; xcb_poly_fill_rectangle(osd->connection, osd->u.shaped.mask_bitmap, osd->u.shaped.mask_gc_back, 1, &rectangle); break; } case XCBOSD_COLORKEY: xcb_change_gc(osd->connection, osd->gc, XCB_GC_FOREGROUND, &osd->u.colorkey.colorkey); if(osd->u.colorkey.sc) { xcb_rectangle_t rectangle = { osd->u.colorkey.sc->output_xoffset, osd->u.colorkey.sc->output_yoffset, osd->u.colorkey.sc->output_width, osd->u.colorkey.sc->output_height }; xcb_poly_fill_rectangle(osd->connection, osd->bitmap, osd->gc, 1, &rectangle); xcb_change_gc(osd->connection, osd->gc, XCB_GC_FOREGROUND, &osd->screen->black_pixel); xcb_rectangle_t rects[4]; int rects_count = 0; for( i = 0; i < 4; i++ ) { if( osd->u.colorkey.sc->border[i].w && osd->u.colorkey.sc->border[i].h ) { rects[rects_count].x = osd->u.colorkey.sc->border[i].x; rects[rects_count].y = osd->u.colorkey.sc->border[i].y; rects[rects_count].width = osd->u.colorkey.sc->border[i].w; rects[rects_count].height = osd->u.colorkey.sc->border[i].h; rects_count++; } if (rects_count > 0) xcb_poly_fill_rectangle(osd->connection, osd->bitmap, osd->gc, rects_count, rects); } } else { xcb_rectangle_t rectangle = { 0, 0, osd->width, osd->height }; xcb_poly_fill_rectangle(osd->connection, osd->bitmap, osd->gc, 1, &rectangle); } break; } osd->clean = WIPED; }
void _cairo_xcb_connection_poly_fill_rectangle (cairo_xcb_connection_t *connection, xcb_drawable_t dst, xcb_gcontext_t gc, uint32_t num_rectangles, xcb_rectangle_t *rectangles) { xcb_poly_fill_rectangle (connection->xcb_connection, dst, gc, num_rectangles, rectangles); }
/** * Fill the specified rectangle on a drawable. * @param d The given drawable. * @param gc The graphic context that controls the fill rules. * @param x The X coordinate of the top-left corner of the rectangle. * @param y The Y coordinate of the top-left corner of the rectangle. * @param width The width of the rectangle. * @param height The height of the rectangle. */ EAPI void ecore_x_drawable_rectangle_fill(Ecore_X_Drawable d, Ecore_X_GC gc, int x, int y, int width, int height) { xcb_rectangle_t rectangle; rectangle.x = x; rectangle.y = y; rectangle.width = width; rectangle.height = height; xcb_poly_fill_rectangle(_ecore_xcb_conn, d, gc, 1, &rectangle); }
void DocWindowFrame::onExposeEvent( xcb_expose_event_t* event) { uint32_t mask = XCB_GC_FUNCTION | XCB_GC_FOREGROUND | XCB_GC_FILL_STYLE | XCB_GC_STIPPLE | XCB_GC_SUBWINDOW_MODE; uint32_t values[] = { XCB_GX_COPY, getApp().getColor(kColorGray), XCB_FILL_STYLE_STIPPLED, getApp().getGrayStipple(), XCB_SUBWINDOW_MODE_CLIP_BY_CHILDREN }; xcb_change_gc(getApp(), mGc, mask, values); xcb_rectangle_t rect = { 0, 0, calcWidthFromClient(), calcHeightFromClient() }; xcb_poly_fill_rectangle(getApp(), mFrameWindow, mGc, 1, &rect); }
xcb_pixmap_t create_bg_pixmap(xcb_connection_t *conn, xcb_screen_t *scr, u_int32_t *resolution, char *color) { xcb_pixmap_t bg_pixmap = xcb_generate_id(conn); xcb_create_pixmap(conn, scr->root_depth, bg_pixmap, scr->root, resolution[0], resolution[1]); /* Generate a Graphics Context and fill the pixmap with background color * (for images that are smaller than your screen) */ xcb_gcontext_t gc = xcb_generate_id(conn); uint32_t values[] = {get_colorpixel(color)}; xcb_create_gc(conn, gc, bg_pixmap, XCB_GC_FOREGROUND, values); xcb_rectangle_t rect = {0, 0, resolution[0], resolution[1]}; xcb_poly_fill_rectangle(conn, bg_pixmap, gc, 1, &rect); xcb_free_gc(conn, gc); return bg_pixmap; }
void event_loop(xcb_window_t window, xcb_gcontext_t graphics_context) { xcb_generic_event_t *event; xcb_rectangle_t r = { 20, 20, 60, 60 }; while(event = xcb_wait_for_event(connection)) { switch(event->response_type) { case XCB_EXPOSE: xcb_poly_fill_rectangle(connection, window, graphics_context, 1, &r); xcb_flush(connection); break; case XCB_KEY_PRESS: return; } } }
void draw_border(client_t *client) { /* Clear root window to erase any old borders */ xcb_aux_clear_window(wm_conf.connection, wm_conf.screen->root); xcb_gcontext_t orange = xcb_generate_id(wm_conf.connection); uint32_t mask = XCB_GC_FOREGROUND; uint32_t value[] = { 0xffffa500 }; xcb_create_gc(wm_conf.connection, orange, wm_conf.screen->root, mask, value); xcb_rectangle_t rect[] = {{ client->rect.x - 2, client->rect.y - 2, client->rect.width + 4, client->rect.height + 4 }}; /* Draw the new border */ xcb_poly_fill_rectangle(wm_conf.connection, wm_conf.screen->root, orange, 1, rect); xcb_free_gc(wm_conf.connection, orange); xcb_map_window(wm_conf.connection, wm_conf.screen->root); xcb_flush(wm_conf.connection); }
static void draw_bar_text(struct bar_box_t *box, const char *s, int len) { uint32_t vals[2]; xcb_rectangle_t rect; vals[0] = nil_.color.bar_fg; vals[1] = nil_.color.bar_bg; if (box->w > 0) { /* clear box before writing text */ rect.x = box->x; rect.y = 0; rect.width = box->w; rect.height = bar_.h; xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND, &vals[1]); xcb_poly_fill_rectangle(nil_.con, bar_.win, bar_.gc, 1, &rect); } /* new pos/size */ rect.width = cal_text_width(s, len); if (NIL_HAS_FLAG(box->flags, BOX_FIXED)) { /* size is not changed */ /* text alignment */ if (NIL_HAS_FLAG(box->flags, BOX_TEXT_CENTER)) { rect.x = box->x + CENTER_H_(box->w, rect.width); } else if (NIL_HAS_FLAG(box->flags, BOX_TEXT_RIGHT)) { rect.x = box->x + box->w - rect.width; } else { rect.x = box->x; } } else if (NIL_HAS_FLAG(box->flags, BOX_RIGHT)) { /* float right */ rect.x = box->x + box->w - rect.width; box->x = rect.x; box->w = rect.width; } else { /* float left */ rect.x = box->x; box->w = rect.width; } NIL_LOG("draw text %d in %d %u", rect.x, box->x, box->w); xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, vals); xcb_image_text_8(nil_.con, len, bar_.win, bar_.gc, rect.x, CENTER_V_(bar_.h), s); }
/* * Handles expose events, that is, draws the window contents. * */ static int handle_expose() { /* re-draw the background */ xcb_rectangle_t border = {0, 0, 300, (15 * font.height) + 8}; xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#000000") }); xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border); set_font(&font); #define txt(x, row, text) \ draw_text_ascii(text, pixmap, pixmap_gc,\ x, (row - 1) * font.height + 4, 300 - x * 2) if (current_step == STEP_WELCOME) { /* restore font color */ set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000")); txt(10, 2, "You have not configured i3 yet."); txt(10, 3, "Do you want me to generate ~/.i3/config?"); txt(85, 5, "Yes, generate ~/.i3/config"); txt(85, 7, "No, I will use the defaults"); /* green */ set_font_colors(pixmap_gc, get_colorpixel("#00FF00"), get_colorpixel("#000000")); txt(25, 5, "<Enter>"); /* red */ set_font_colors(pixmap_gc, get_colorpixel("#FF0000"), get_colorpixel("#000000")); txt(31, 7, "<ESC>"); } if (current_step == STEP_GENERATE) { set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000")); txt(10, 2, "Please choose either:"); txt(85, 4, "Win as default modifier"); txt(85, 5, "Alt as default modifier"); txt(10, 7, "Afterwards, press"); txt(85, 9, "to write ~/.i3/config"); txt(85, 10, "to abort"); /* the not-selected modifier */ if (modifier == MOD_Mod4) txt(31, 5, "<Alt>"); else txt(31, 4, "<Win>"); /* the selected modifier */ set_font(&bold_font); set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000")); if (modifier == MOD_Mod4) txt(10, 4, "-> <Win>"); else txt(10, 5, "-> <Alt>"); /* green */ set_font(&font); set_font_colors(pixmap_gc, get_colorpixel("#00FF00"), get_colorpixel("#000000")); txt(25, 9, "<Enter>"); /* red */ set_font_colors(pixmap_gc, get_colorpixel("#FF0000"), get_colorpixel("#000000")); txt(31, 10, "<ESC>"); } /* Copy the contents of the pixmap to the real window */ xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, 500); xcb_flush(conn); return 1; }
void draw_gc(xcb_window_t win) { // the only problem to draw bgr24 it bps=4 but 3, if depth=24, /* fmt depth bps 32 32 4 bgr24 24 4 16 16 2 8 8 1 0 0 0 */ //draw something in parent window for test //w = s->root; xcb_gcontext_t g_solid; uint32_t mask; uint32_t values[2]; xcb_rectangle_t r = { 0, 0, 10,10 }; xcb_rectangle_t r2 = { 20, 20, 100,100 }; xcb_connection_t *c = G.conn; if(win==0) { win=G.root; // atach to root will cause error=Resource temporary unavailable } xcb_map_window(c, win); xcb_flush(c); g_solid = xcb_generate_id(c); mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = G.s->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS; xcb_create_gc(c, g_solid, win, 0,NULL); xcb_change_gc(c, g_solid, mask, values); xcb_poly_fill_rectangle(c, win, g_solid, 1, &r2); xcb_flush(c); xcb_free_gc(c,g_solid); if(1){ //getimage xcb_get_image_cookie_t cookie; xcb_get_image_reply_t *reply; xcb_generic_error_t *error; int psize= r.width * r.height * G.s->root_depth/8; psize = r.width * r.height * 4; //correct static uint8_t *pbuf = NULL; xcb_void_cookie_t ck; if( pbuf == NULL){ pbuf = malloc(psize); printf("malloc pbuf=0x%x size=%d\n",pbuf, psize); memset(pbuf, 0x18, psize); } #if 0 cookie = xcb_get_image (c, XCB_IMAGE_FORMAT_Z_PIXMAP, win, r.x, r.y, r.width, r.height, ~0); reply = xcb_get_image_reply (c, cookie, &error); if (reply == NULL){ perror("get_image_replay"); return; } if (error != NULL) { perror("error in xcb_get_image"); free(error); } else { uint32_t bytes = xcb_get_image_data_length(reply); uint8_t *idata = xcb_get_image_data(reply); printf("get_image size=%d p=%p\n", bytes, idata); memcpy(pbuf, idata, bytes); printf("root_depth=%d\n", G.s->root_depth); psize=bytes; } free(reply); #endif //draw image with xcb_put_image // creat gc and draw to parent window xcb_gcontext_t g; g = xcb_generate_id(c); xcb_create_gc(c, g, win, 0,NULL); memset(pbuf, 0xf8, psize); int i=0; uint8_t *p2=pbuf; //fmt = bgr24 for( i=0; i<psize; ){ *(p2+i)= 0; i++; //blue *(p2+i)= 0xff; i++; //green *(p2+i)= 0; i++; //red *(p2+i)= 0x80; i++; //?? } ck = xcb_put_image_checked(c, XCB_IMAGE_FORMAT_Z_PIXMAP, win, g, r.width, r.height, r.x,r.y, 0, G.s->root_depth, psize, pbuf); xcb_flush(c); #if 0 //BadMatch=8 BadLength=16 xcb_generic_error_t *err; err = xcb_request_check (c, ck); if (err) { int code = err->error_code; free (err); printf("put image error %d\n", code); assert (code != 0); } xcb_free_gc(c, g); #endif } }
int main(void) { xcb_connection_t *c; xcb_screen_t *s; xcb_window_t w; xcb_gcontext_t g; xcb_generic_event_t *e; uint32_t mask; uint32_t values[2]; int done = 0; /* open connection with the server */ c = xcb_connect(NULL,NULL); if (xcb_connection_has_error(c)) { printf("Cannot open display\n"); exit(1); } /* get the first screen */ s = xcb_setup_roots_iterator( xcb_get_setup(c) ).data; G.conn = c; G.s= s; //enable mouse event xcb_cursor_t cursor; xcb_font_t cursor_font=0; short glyph = 0x34; //cross xcb_grab_pointer_cookie_t grab_cookie; xcb_grab_pointer_reply_t *grab_reply; xcb_generic_error_t *err; cursor = xcb_generate_id (c); if (!cursor_font) { cursor_font = xcb_generate_id (c); xcb_open_font (c, cursor_font, strlen ("cursor"), "cursor"); } xcb_create_glyph_cursor (c, cursor, cursor_font, cursor_font, glyph, glyph + 1, 0, 0, 0, 0xffff, 0xffff, 0xffff); /* rgb, rgb */ grab_cookie = xcb_grab_pointer(c, 0, s->root, XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, s->root, cursor, XCB_TIME_CURRENT_TIME); assert(grab_reply!=NULL); grab_reply = xcb_grab_pointer_reply (c, grab_cookie, &err); if (grab_reply->status != XCB_GRAB_STATUS_SUCCESS) printf("Can't grab the mouse."); printf("grab pointer cookie=0x%x\n", grab_cookie); xcb_allow_events (c, XCB_ALLOW_ASYNC_POINTER, XCB_TIME_CURRENT_TIME); xcb_flush (c); // xcb_allow_events (c, XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); xcb_flush (c); while (!done ) { e = xcb_wait_for_event(c); if(e==NULL) printf("wait event error\n"); //printf("\revent=>%d", e->response_type); switch (e->response_type & ~0x80) { case XCB_EXPOSE: /* draw or redraw the window */ printf("XCB_EXPOSE\n"); draw_gc(w); break; case XCB_MOTION_NOTIFY: { static xcb_window_t oldw; xcb_button_press_event_t *bp = (xcb_button_press_event_t *)e; w = bp->child; /* window selected */ if(oldw!=w){ oldw = w; printf("windowid = %x\n", w); } //draw it draw_gc(w); } break; case XCB_BUTTON_PRESS: { xcb_button_press_event_t *bp = (xcb_button_press_event_t *)e; w = bp->child; /* window selected */ if (w== XCB_WINDOW_NONE){ printf("window select is root\n"); w=s->root; } else printf("window = %x\n", w); draw_gc(w); done=1; printf("grab a child\n"); break; } } free(e); } xcb_ungrab_pointer(c, XCB_TIME_CURRENT_TIME); draw_byxid(w); return 0; #if 0 /* create window */ w = xcb_generate_id(c); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = s->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS; xcb_create_window(c, s->root_depth, w, s->root, 10, 10, 100, 100, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, s->root_visual, mask, values); /* map (show) the window */ xcb_map_window(c, w); xcb_flush(c); /* event loop */ while (!done && (e = xcb_wait_for_event(c))) { switch (e->response_type & ~0x80) { case XCB_EXPOSE: /* draw or redraw the window */ xcb_poly_fill_rectangle(c, w, g, 1, &r); xcb_flush(c); break; case XCB_KEY_PRESS: /* exit on key press */ //gwj done = 1; break; } free(e); } /* close connection to server */ xcb_disconnect(c); return 0; if(0){ //draw image with xcb_put_image // creat gc and draw to parent window xcb_gcontext_t g; g = xcb_generate_id(c); xcb_create_gc(c, g, child, 0,NULL); //xcb_poly_fill_rectangle(c, w, g, 1, &r); xcb_flush(c); int psize=geo->width * geo->height* (geo->depth/8); uint8_t *pbuf = malloc(psize); xcb_void_cookie_t ck; printf("malloc pbuf=0x%x size=%d\n",pbuf, psize); memset(pbuf, 0x18, psize); ck = xcb_put_image_checked(c, XCB_IMAGE_FORMAT_Z_PIXMAP, child, g, geo->width, geo->height , 0, 0, 0, geo->depth, psize, pbuf); //BadMatch=8 BadLength=16 xcb_generic_error_t *err; err = xcb_request_check (c, ck); if (err) { int code = err->error_code; free (err); printf("put image error %d\n", code); assert (code != 0); } } printf("depth =%d\n", geo->depth); /* create black graphics context */ #endif }
static void focus (xcb_window_t win, int mode) { uint32_t values[1]; short w, h, b, o; if (!win) return; xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL); if (mode == RESIZE) { values[0] = RESIZE_COLOR; xcb_change_window_attributes(conn, win, XCB_CW_BORDER_PIXEL, values); return; } if (!geom) return; w = (short)geom->width; h = (short)geom->height; b = (unsigned short)BORDERWIDTH; o = (unsigned short)OUTER; xcb_rectangle_t inner[] = { /* you're not supposed to understand this. */ { w,0,b-o , h+ b- o}, { w+b +o, 0, b -o, h+ b - o}, { 0,h ,w+b -o,b- o }, { 0,h +b+ o, w+ b- o, b -o}, { w+b+o,b +h +o,b,b} }; xcb_rectangle_t outer[] = { {w + b - o, 0, o, h + b * 2}, {w + b, 0, o, h + b * 2}, {0, h + b - o, w + b * 2, o}, {0, h + b, w + b * 2, o}, {1, 1, 1, 1} }; xcb_pixmap_t pmap = xcb_generate_id(conn); xcb_create_pixmap(conn, scr->root_depth, pmap, win, geom->width + (BORDERWIDTH * 2), geom->height + (BORDERWIDTH * 2)); xcb_gcontext_t gc = xcb_generate_id(conn); xcb_create_gc(conn, gc, pmap, 0, NULL); values[0] = OUTER_COLOR; xcb_change_gc(conn, gc, XCB_GC_FOREGROUND, values); xcb_poly_fill_rectangle(conn, pmap, gc, 5, outer); values[0] = mode ? FOCUSCOL : UNFOCUSCOL; xcb_change_gc(conn, gc, XCB_GC_FOREGROUND, values); xcb_poly_fill_rectangle(conn, pmap, gc, 5, inner); values[0] = pmap; xcb_change_window_attributes(conn, win, XCB_CW_BORDER_PIXMAP, values); if (mode) { xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME); if (win != (*focuswin)) { focus((*focuswin), INACTIVE); (*focuswin) = win; } } xcb_free_pixmap(conn, pmap); xcb_free_gc(conn, gc); }
void xcbosd_blend(xcbosd *osd, vo_overlay_t *overlay) { xcb_alloc_color_cookie_t alloc_color_cookie; xcb_alloc_color_reply_t *alloc_color_reply; if (osd->clean==UNDEFINED) xcbosd_clear(osd); /* Workaround. Colorkey mode needs sc data before the clear. */ if (overlay->rle) { int i, x, y, len, width; int use_clip_palette, max_palette_colour[2]; uint32_t palette[2][OVL_PALETTE_SIZE]; max_palette_colour[0] = -1; max_palette_colour[1] = -1; for (i=0, x=0, y=0; i<overlay->num_rle; i++) { len = overlay->rle[i].len; while (len > 0) { use_clip_palette = 0; if (len > overlay->width) { width = overlay->width; len -= overlay->width; } else { width = len; len = 0; } if ((y >= overlay->hili_top) && (y <= overlay->hili_bottom) && (x <= overlay->hili_right)) { if ((x < overlay->hili_left) && (x + width - 1 >= overlay->hili_left)) { width -= overlay->hili_left - x; len += overlay->hili_left - x; } else if (x > overlay->hili_left) { use_clip_palette = 1; if (x + width - 1 > overlay->hili_right) { width -= overlay->hili_right - x; len += overlay->hili_right - x; } } } if (overlay->rle[i].color > max_palette_colour[use_clip_palette]) { int j; clut_t *src_clut; uint8_t *src_trans; if (use_clip_palette) { src_clut = (clut_t *)&overlay->hili_color; src_trans = (uint8_t *)&overlay->hili_trans; } else { src_clut = (clut_t *)&overlay->color; src_trans = (uint8_t *)&overlay->trans; } for (j=max_palette_colour[use_clip_palette]+1; j<=overlay->rle[i].color; j++) { if (src_trans[j]) { if (1) { int red, green, blue; int y, u, v, r, g, b; y = saturate(src_clut[j].y, 16, 235); u = saturate(src_clut[j].cb, 16, 240); v = saturate(src_clut[j].cr, 16, 240); y = (9 * y) / 8; r = y + (25 * v) / 16 - 218; red = (65536 * saturate(r, 0, 255)) / 256; g = y + (-13 * v) / 16 + (-25 * u) / 64 + 136; green = (65536 * saturate(g, 0, 255)) / 256; b = y + 2 * u - 274; blue = (65536 * saturate(b, 0, 255)) / 256; alloc_color_cookie = xcb_alloc_color(osd->connection, osd->cmap, red, green, blue); alloc_color_reply = xcb_alloc_color_reply(osd->connection, alloc_color_cookie, NULL); palette[use_clip_palette][j] = alloc_color_reply->pixel; free(alloc_color_reply); } else { if (src_clut[j].y > 127) { palette[use_clip_palette][j] = osd->screen->white_pixel; } else { palette[use_clip_palette][j] = osd->screen->black_pixel; } } } else { palette[use_clip_palette][j] = TRANSPARENT; } } max_palette_colour[use_clip_palette] = overlay->rle[i].color; } if(palette[use_clip_palette][overlay->rle[i].color] != TRANSPARENT) { xcb_change_gc(osd->connection, osd->gc, XCB_GC_FOREGROUND, &palette[use_clip_palette][overlay->rle[i].color]); xcb_rectangle_t rectangle = { overlay->x + x, overlay->y + y, width, 1 }; xcb_poly_fill_rectangle(osd->connection, osd->bitmap, osd->gc, 1, &rectangle); if(osd->mode==XCBOSD_SHAPED) xcb_poly_fill_rectangle(osd->connection, osd->u.shaped.mask_bitmap, osd->u.shaped.mask_gc, 1, &rectangle); } x += width; if (x == overlay->width) { x = 0; y++; } } } osd->clean = DRAWN; } }
Xpost_View_Window * xpost_view_win_new(int xorig, int yorig, int width, int height) { xcb_screen_iterator_t iter; xcb_rectangle_t rect; xcb_get_geometry_reply_t *geom; Xpost_View_Window *win; int scrno; unsigned int values[3]; unsigned int mask; win = (Xpost_View_Window *)calloc(1, sizeof(Xpost_View_Window)); if (!win) return NULL; win->width = width; win->height = height; /* open a connection */ win->c = xcb_connect(NULL, &scrno); if (xcb_connection_has_error(win->c)) { fprintf(stderr, "Fail to connect to the X server\n"); goto free_win; } /* get the screen */ iter = xcb_setup_roots_iterator(xcb_get_setup(win->c)); for (; iter.rem; --scrno, xcb_screen_next(&iter)) { if (scrno == 0) { win->scr = iter.data; break; } } /* get the depth of the screen */ geom = xcb_get_geometry_reply(win->c, xcb_get_geometry(win->c, win->scr->root), 0); if (!geom) { fprintf(stderr, "Fail to the geometry of the root window\n"); goto disconnect_c; } win->depth = geom->depth; free(geom); /* create the window */ win->window = xcb_generate_id(win->c); mask = XCB_CW_BACK_PIXMAP | XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = XCB_NONE; values[1] = win->scr->white_pixel; values[2] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_KEY_RELEASE; xcb_create_window(win->c, XCB_COPY_FROM_PARENT, win->window, win->scr->root, xorig, yorig, width, height, 5, XCB_WINDOW_CLASS_INPUT_OUTPUT, win->scr->root_visual, mask, values); /* set title of the window */ xcb_change_property(win->c, XCB_PROP_MODE_REPLACE, win->window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, sizeof("Xpost viewer") - 1, "Xpost viewer"); /* set background context */ win->gc = xcb_generate_id(win->c); values[0] = win->scr->white_pixel; values[1] = 0; xcb_create_gc(win->c, win->gc, win->window, XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES, values); /* set background pixmap */ rect.x = 0; rect.y = 0; rect.width = width; rect.height = height; win->pixmap = xcb_generate_id(win->c); xcb_create_pixmap(win->c, win->depth, win->pixmap, win->window, width, height); xcb_poly_fill_rectangle(win->c, win->pixmap, win->gc, 1, &rect); xcb_map_window(win->c, win->window); xcb_flush(win->c); return win; disconnect_c: xcb_disconnect(win->c); free_win: free(win); return NULL; }
void config_bar() { unsigned int i; int len, pad; xcb_rectangle_t rect; uint32_t vals[2]; char text[3]; struct bar_box_t *box; /* workspace selection area */ box = &bar_.box[BAR_WS]; box->x = 0; box->w = bar_.h * cfg_.num_workspaces; box->flags = BOX_FIXED; box->click = &click_ws; /* colors */ vals[0] = nil_.color.bar_fg; vals[1] = nil_.color.bar_bg; xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND, &vals[1]); rect.width = bar_.w; rect.height = bar_.h; rect.x = 0; rect.y = 0; xcb_poly_fill_rectangle(nil_.con, bar_.win, bar_.gc, 1, &rect); /* workspace numbers */ xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, vals); rect.x = 0; rect.y = (rect.height + nil_.font.ascent + nil_.font.descent) / 2 - nil_.font.descent; rect.width = bar_.h; for (i = 1; i <= cfg_.num_workspaces; ++i) { len = snprintf(text, sizeof(text), "%u", i); pad = (rect.width - cal_text_width(text, len)) / 2; /* to align center */ xcb_image_text_8(nil_.con, len, bar_.win, bar_.gc, rect.x + pad, rect.y, text); rect.x += rect.width; } /* layout symbol (next to ws) */ box = &bar_.box[BAR_SYM]; box->x = 0 + bar_.box[BAR_WS].w; box->w = 30; box->flags = BOX_FIXED | BOX_TEXT_CENTER; box->click = &click_sym; /* icon tray (right aligned) */ box = &bar_.box[BAR_ICON]; box->x = bar_.w; box->w = 0; /* no icon yet */ box->flags = BOX_RIGHT; box->click = 0; /* status (right aligned) */ box = &bar_.box[BAR_STATUS]; box->x = bar_.w - bar_.box[BAR_ICON].w; box->w = 0; /* empty */ box->flags = BOX_RIGHT; box->click = 0; /* task (remain) */ box = &bar_.box[BAR_TASK]; box->x = bar_.box[BAR_SYM].x + bar_.box[BAR_SYM].w; box->w = bar_.box[BAR_STATUS].x - bar_.box[BAR_TASK].x; box->flags = BOX_LEFT; box->click = 0; }
int main(void) { xcb_connection_t *c; xcb_screen_t *s; xcb_window_t w; xcb_gcontext_t g; xcb_generic_event_t *e; uint32_t mask; uint32_t values[2]; int done = 0; xcb_rectangle_t r = { 20, 20, 60, 60 }; /* open connection with the server */ c = xcb_connect(NULL,NULL); if (xcb_connection_has_error(c)) { printf("Cannot open display\n"); exit(1); } /* get the first screen */ s = xcb_setup_roots_iterator( xcb_get_setup(c) ).data; /* create black graphics context */ g = xcb_generate_id(c); w = s->root; mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = s->black_pixel; values[1] = 0; xcb_create_gc(c, g, w, mask, values); /* create window */ w = xcb_generate_id(c); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = s->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS; xcb_create_window(c, s->root_depth, w, s->root, 10, 10, 100, 100, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, s->root_visual, mask, values); /* map (show) the window */ xcb_map_window(c, w); xcb_flush(c); /* event loop */ while (!done && (e = xcb_wait_for_event(c))) { switch (e->response_type & ~0x80) { case XCB_EXPOSE: /* draw or redraw the window */ xcb_poly_fill_rectangle(c, w, g, 1, &r); xcb_flush(c); break; case XCB_KEY_PRESS: /* exit on key press */ done = 1; break; } free(e); } /* close connection to server */ xcb_disconnect(c); return 0; }