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 _cairo_xcb_connection_change_gc (cairo_xcb_connection_t *connection, xcb_gcontext_t gc, uint32_t value_mask, uint32_t *values) { xcb_change_gc (connection->xcb_connection, gc, value_mask, values); }
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 drawButton (xcb_connection_t *connection, xcb_screen_t *screen, xcb_window_t window, int16_t x1, int16_t y1, const char *label ) { uint8_t length = strlen (label); int16_t inset = 2; int16_t width = 7 * length + 2 * (inset + 1); int16_t height = 13 + 2 * (inset + 1); xcb_point_t points[5]; points[0].x = x1; points[0].y = y1; points[1].x = x1 + width; points[1].y = y1; points[2].x = x1 + width; points[2].y = y1 - height; points[3].x = x1; points[3].y = y1 - height; points[4].x = x1; points[4].y = y1; xcb_colormap_t colors[2]; colors[0]=screen->black_pixel; colors[1]=screen->white_pixel; xcb_gcontext_t gc = getFontGC2 (connection, screen, window,colors, "7x13"); uint32_t gcv[1]= {screen->black_pixel}; xcb_change_gc(connection,gc, XCB_GC_FOREGROUND, gcv); xcb_void_cookie_t lineCookie = xcb_poly_line_checked (connection, XCB_COORD_MODE_ORIGIN, window, gc, 5, points ); testCookie (lineCookie, connection, "can't draw lines"); xcb_void_cookie_t textCookie = xcb_image_text_8_checked (connection, length, window, gc, x1 + inset + 1, y1 - inset - 1, label ); testCookie (textCookie, connection, "can't paste text"); xcb_void_cookie_t gcCookie = xcb_free_gc (connection, gc); testCookie (gcCookie, connection, "can't free gc"); };
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); }
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); }
void DocWindowFrame::drawDragOutline( int32_t x, int32_t y) { uint32_t mask = XCB_GC_FUNCTION | XCB_GC_LINE_WIDTH | XCB_GC_SUBWINDOW_MODE; uint32_t values[] = {XCB_GX_XOR, 2, XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS }; xcb_rectangle_t rect; rect.x = x; rect.y = y; rect.width = calcWidthFromClient(); rect.height = calcHeightFromClient(); xcb_change_gc(getApp(), mGc, mask, values); xcb_poly_rectangle(getApp(), mFrameParentWindow, mGc, 1, &rect); }
/* * Convenience-wrapper around xcb_change_gc which saves us declaring a variable * */ void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value) { xcb_change_gc(conn, gc, mask, &value); }
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 } }
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; }
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; } }