static void _e_alert_create(void) { uint32_t mask, mask_list[4]; int wx = 0, wy = 0; wx = ((sw - WINDOW_WIDTH) / 2); wy = ((sh - WINDOW_HEIGHT) / 2); font = xcb_generate_id(conn); xcb_open_font(conn, font, strlen("fixed"), "fixed"); /* create main window */ mask = (XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK); mask_list[0] = screen->white_pixel; mask_list[1] = screen->black_pixel; mask_list[2] = 1; mask_list[3] = (XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE); win = xcb_generate_id(conn); xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, screen->root, wx, wy, WINDOW_WIDTH, WINDOW_HEIGHT, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, mask_list); /* create button 1 */ mask_list[3] = (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE); btn1 = xcb_generate_id(conn); xcb_create_window(conn, XCB_COPY_FROM_PARENT, btn1, win, -100, -100, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, mask_list); xcb_map_window(conn, btn1); /* create button 2 */ btn2 = xcb_generate_id(conn); xcb_create_window(conn, XCB_COPY_FROM_PARENT, btn2, win, -100, -100, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, mask_list); xcb_map_window(conn, btn2); /* create drawing gc */ mask = (XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT); mask_list[0] = screen->black_pixel; mask_list[1] = screen->white_pixel; mask_list[2] = font; gc = xcb_generate_id(conn); xcb_create_gc(conn, gc, win, mask, mask_list); }
void ShellXcb::create_window() { win_ = xcb_generate_id(c_); uint32_t value_mask, value_list[32]; value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; value_list[0] = scr_->black_pixel; value_list[1] = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY; xcb_create_window(c_, XCB_COPY_FROM_PARENT, win_, scr_->root, 0, 0, settings_.initial_width, settings_.initial_height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, scr_->root_visual, value_mask, value_list); xcb_intern_atom_cookie_t utf8_string_cookie = intern_atom_cookie(c_, "UTF8_STRING"); xcb_intern_atom_cookie_t _net_wm_name_cookie = intern_atom_cookie(c_, "_NET_WM_NAME"); xcb_intern_atom_cookie_t wm_protocols_cookie = intern_atom_cookie(c_, "WM_PROTOCOLS"); xcb_intern_atom_cookie_t wm_delete_window_cookie = intern_atom_cookie(c_, "WM_DELETE_WINDOW"); // set title xcb_atom_t utf8_string = intern_atom(c_, utf8_string_cookie); xcb_atom_t _net_wm_name = intern_atom(c_, _net_wm_name_cookie); xcb_change_property(c_, XCB_PROP_MODE_REPLACE, win_, _net_wm_name, utf8_string, 8, settings_.name.size(), settings_.name.c_str()); // advertise WM_DELETE_WINDOW wm_protocols_ = intern_atom(c_, wm_protocols_cookie); wm_delete_window_ = intern_atom(c_, wm_delete_window_cookie); xcb_change_property(c_, XCB_PROP_MODE_REPLACE, win_, wm_protocols_, XCB_ATOM_ATOM, 32, 1, &wm_delete_window_); }
xcb_window_t create_window() { // http://www.x.org/releases/current/doc/xproto/x11protocol.html#requests:CreateWindow // http://www.x.org/archive/current/doc/man/man3/xcb_create_window.3.xhtml // // N.B. xcb's order corresponds to the order of the wire. // You can look at the protocol encoding: http://www.x.org/releases/current/doc/xproto/x11protocol.html#Encoding::Requests uint32_t mask; uint32_t values[2]; xcb_window_t window; xcb_void_cookie_t cookie; mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS; window = xcb_generate_id(connection); cookie = xcb_create_window(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0, 0, 640, 480, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); xcb_map_window(connection, window); return window; }
void update_root(monitor_t *m, xcb_rectangle_t *rect) { xcb_rectangle_t last_rect = m->rectangle; m->rectangle = *rect; if (m->root == XCB_NONE) { uint32_t values[] = {XCB_EVENT_MASK_ENTER_WINDOW}; m->root = xcb_generate_id(dpy); xcb_create_window(dpy, XCB_COPY_FROM_PARENT, m->root, root, rect->x, rect->y, rect->width, rect->height, 0, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_COPY_FROM_PARENT, XCB_CW_EVENT_MASK, values); xcb_icccm_set_wm_class(dpy, m->root, sizeof(ROOT_WINDOW_IC), ROOT_WINDOW_IC); window_lower(m->root); if (focus_follows_pointer) { window_show(m->root); } } else { window_move_resize(m->root, rect->x, rect->y, rect->width, rect->height); put_status(SBSC_MASK_MONITOR_GEOMETRY, "monitor_geometry 0x%08X %ux%u+%i+%i\n", m->id, rect->width, rect->height, rect->x, rect->y); } for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { if (n->client == NULL) { continue; } adapt_geometry(&last_rect, rect, n); } arrange(m, d); } }
Client *Client::create(const Rect& rect, int screenNumber, const String &clazz, const String &instance, bool movable) { WindowManager *wm = WindowManager::instance(); xcb_connection_t* conn = wm->connection(); xcb_screen_t* scr = wm->screens().at(screenNumber); xcb_window_t window = xcb_generate_id(conn); const uint32_t values[] = { scr->black_pixel, XCB_GRAVITY_NORTH_WEST, XCB_GRAVITY_NORTH_WEST, 1, (XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE) }; warning() << "creating client window" << rect; xcb_create_window(conn, XCB_COPY_FROM_PARENT, window, scr->root, rect.x, rect.y, rect.width, rect.height, 0, XCB_COPY_FROM_PARENT, XCB_COPY_FROM_PARENT, XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY | XCB_CW_WIN_GRAVITY | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, values); xcb_icccm_wm_hints_t wmHints; xcb_icccm_wm_hints_set_none(&wmHints); xcb_icccm_wm_hints_set_input(&wmHints, 0); xcb_icccm_set_wm_hints(conn, window, &wmHints); xcb_size_hints_t wmNormalHints; memset(&wmNormalHints, 0, sizeof(wmNormalHints)); xcb_icccm_size_hints_set_position(&wmNormalHints, 1, rect.x, rect.y); xcb_icccm_size_hints_set_size(&wmNormalHints, 1, rect.width, rect.height); xcb_icccm_set_wm_normal_hints(conn, window, &wmNormalHints); String className = clazz + ' ' + instance; className[clazz.size()] = '\0'; xcb_icccm_set_wm_class(conn, window, className.size(), className.constData()); Client *ptr = new Client(window); ptr->mMovable = movable; ptr->mRect = rect; ptr->mOwned = true; ptr->mScreenNumber = screenNumber; ptr->init(); ptr->mNoFocus = true; Workspace *ws = wm->activeWorkspace(screenNumber); assert(ws); ptr->mWorkspace = ws; ws->addClient(ptr); wm->js().onClient(ptr); ptr->complete(); sClients[window] = ptr; return ptr; }
/** Initialize systray information in X. */ void systray_init(void) { xcb_intern_atom_cookie_t atom_systray_q; xcb_intern_atom_reply_t *atom_systray_r; char *atom_name; xcb_screen_t *xscreen = globalconf.screen; globalconf.systray.window = xcb_generate_id(globalconf.connection); xcb_create_window(globalconf.connection, xscreen->root_depth, globalconf.systray.window, xscreen->root, -1, -1, 1, 1, 0, XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL); atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", globalconf.default_screen); if(!atom_name) fatal("error getting systray atom name"); atom_systray_q = xcb_intern_atom_unchecked(globalconf.connection, false, a_strlen(atom_name), atom_name); p_delete(&atom_name); atom_systray_r = xcb_intern_atom_reply(globalconf.connection, atom_systray_q, NULL); if(!atom_systray_r) fatal("error getting systray atom"); globalconf.systray.atom = atom_systray_r->atom; p_delete(&atom_systray_r); }
static void weston_dnd_start(struct weston_wm *wm, xcb_window_t owner) { uint32_t values[1], version = 4; wm->dnd_window = xcb_generate_id(wm->conn); values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE; xcb_create_window(wm->conn, XCB_COPY_FROM_PARENT, wm->dnd_window, wm->screen->root, 0, 0, 8192, 8192, 0, XCB_WINDOW_CLASS_INPUT_ONLY, wm->screen->root_visual, XCB_CW_EVENT_MASK, values); xcb_change_property(wm->conn, XCB_PROP_MODE_REPLACE, wm->dnd_window, wm->atom.xdnd_aware, XCB_ATOM_ATOM, 32, /* format */ 1, &version); xcb_map_window(wm->conn, wm->dnd_window); wm->dnd_owner = owner; }
int main() { /* Open the connection to the X server */ xcb_connection_t *connection = xcb_connect(NULL, NULL); /* Get the first screen */ const xcb_setup_t *setup = xcb_get_setup(connection); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup); xcb_screen_t *screen = iter.data; /* Create the window */ xcb_window_t window = xcb_generate_id(connection); xcb_create_window(connection, /* Connection */ XCB_COPY_FROM_PARENT, /* depth (same as root) */ window, /* window Id */ screen->root, /* parent window */ 0, 0, /* x, y */ 150, 150, /* width, height */ 10, /* border_width */ XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ screen->root_visual, /* visual */ 0, NULL); /* masks, not used yet */ /* Map the window on the screen */ xcb_map_window(connection, window); /* Make sure commands are sent before we pause so that the window gets shown */ xcb_flush(connection); pause(); /* hold client until Ctrl-C */ xcb_disconnect(connection); return 0; }
void X11WindowedBackend::createWindow() { Xcb::Atom protocolsAtom(QByteArrayLiteral("WM_PROTOCOLS"), false, m_connection); Xcb::Atom deleteWindowAtom(QByteArrayLiteral("WM_DELETE_WINDOW"), false, m_connection); for (int i = 0; i < initialOutputCount(); ++i) { Output o; o.window = xcb_generate_id(m_connection); uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; const uint32_t values[] = { m_screen->black_pixel, XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_EXPOSURE }; o.size = initialWindowSize(); if (!m_windows.isEmpty()) { const auto &p = m_windows.last(); o.internalPosition = QPoint(p.internalPosition.x() + p.size.width(), 0); } xcb_create_window(m_connection, XCB_COPY_FROM_PARENT, o.window, m_screen->root, 0, 0, o.size.width(), o.size.height(), 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, values); o.winInfo = new NETWinInfo(m_connection, o.window, m_screen->root, NET::WMWindowType, NET::Properties2()); o.winInfo->setWindowType(NET::Normal); o.winInfo->setPid(QCoreApplication::applicationPid()); QIcon windowIcon = QIcon::fromTheme(QStringLiteral("kwin")); auto addIcon = [&o, &windowIcon] (const QSize &size) { if (windowIcon.actualSize(size) != size) { return; } NETIcon icon; icon.data = windowIcon.pixmap(size).toImage().bits(); icon.size.width = size.width(); icon.size.height = size.height(); o.winInfo->setIcon(icon, false); }; addIcon(QSize(16, 16)); addIcon(QSize(32, 32)); addIcon(QSize(48, 48)); xcb_map_window(m_connection, o.window); m_protocols = protocolsAtom; m_deleteWindowProtocol = deleteWindowAtom; xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, o.window, m_protocols, XCB_ATOM_ATOM, 32, 1, &m_deleteWindowProtocol); m_windows << o; } updateWindowTitle(); xcb_flush(m_connection); }
static EventdNdSurface * _eventd_nd_xcb_surface_new(EventdNdBackendContext *context, EventdNdNotification *notification, gint width, gint height) { guint32 selmask = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; guint32 selval[] = { 0, 0, 1, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE, context->map }; EventdNdSurface *self; self = g_new0(EventdNdSurface, 1); self->notification = notification; self->context = context; self->width = width; self->height = height; self->window = xcb_generate_id(context->xcb_connection); xcb_create_window(context->xcb_connection, context->depth->depth, /* depth */ self->window, context->screen->root, /* parent window */ 0, 0, /* x, y */ width, height, /* width, height */ 0, /* border_width */ XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ context->visual->visual_id, /* visual */ selmask, selval); /* masks */ self->surface = cairo_xcb_surface_create(self->context->xcb_connection, self->window, self->context->visual, self->width, self->height); g_hash_table_insert(context->bubbles, GUINT_TO_POINTER(self->window), self); _eventd_nd_xcb_surface_shape(self); return self; }
void XWaylandManager::wmSelection() { m_selRequest.requestor = XCB_NONE; quint32 values[1]; values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE; m_selWindow = xcb_generate_id(Xcb::connection()); xcb_create_window(Xcb::connection(), XCB_COPY_FROM_PARENT, m_selWindow, Xcb::rootWindow(), 0, 0, 10, 10, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, Xcb::rootVisual(), XCB_CW_EVENT_MASK, values); xcb_set_selection_owner(Xcb::connection(), m_selWindow, Xcb::resources()->atoms->clipboard_manager, XCB_TIME_CURRENT_TIME); quint32 mask = XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE; xcb_xfixes_select_selection_input(Xcb::connection(), m_selWindow, Xcb::resources()->atoms->clipboard, mask); //weston_wm_set_selection }
int main(void) { xcb_connection_t *conn; xcb_screen_t *screen; xcb_window_t win; xcb_gcontext_t gcontext; xcb_generic_event_t *event; uint32_t mask; uint32_t values[2]; /* open connection with the server */ conn = xcb_connect(NULL,NULL); if (xcb_connection_has_error(conn)) { printf("Cannot open display\n"); exit(1); } /* get the first screen */ screen = xcb_setup_roots_iterator( xcb_get_setup(conn) ).data; /* create black graphics gcontext */ gcontext = xcb_generate_id(conn); win = screen->root; mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = screen->black_pixel; values[1] = 0; xcb_create_gc(conn, gcontext, win, mask, values); /* create window */ win = xcb_generate_id(conn); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE; xcb_create_window(conn, screen->root_depth, win, screen->root, 10, 10, 100, 100, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); /* map (show) the window */ xcb_map_window(conn, win); xcb_flush(conn); cterm_add_event_listener(XCB_KEY_PRESS, output_string); cterm_add_event_listener(XCB_KEY_PRESS, close_window); /* event loop */ while (!done) { event = xcb_poll_for_event(conn); if(event == NULL) continue; cterm_handle_event(event); free(event); } /* close connection to server */ xcb_disconnect(conn); cterm_free_event_handlers(); return 0; }
xcb_window_t open_fullscreen_window(xcb_connection_t *conn, xcb_screen_t *scr, char *color, xcb_pixmap_t pixmap) { uint32_t mask = 0; uint32_t values[3]; xcb_window_t win = xcb_generate_id(conn); if (pixmap == XCB_NONE) { mask |= XCB_CW_BACK_PIXEL; values[0] = get_colorpixel(color); } else { mask |= XCB_CW_BACK_PIXMAP; values[0] = pixmap; } mask |= XCB_CW_OVERRIDE_REDIRECT; values[1] = 1; mask |= XCB_CW_EVENT_MASK; values[2] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_VISIBILITY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY; xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, /* the window id */ scr->root, /* parent == root */ 0, 0, scr->width_in_pixels, scr->height_in_pixels, /* dimensions */ 0, /* border = 0, we draw our own */ XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */ mask, values); char *name = "i3lock"; xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen(name), name); /* Map the window (= make it visible) */ xcb_map_window(conn, win); /* Raise window (put it on top) */ values[0] = XCB_STACK_MODE_ABOVE; xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_STACK_MODE, values); /* Ensure that the window is created and set up before returning */ xcb_aux_sync(conn); return win; }
/** Initialize systray information in X. * \param phys_screen Physical screen. */ void systray_init(int phys_screen) { xcb_client_message_event_t ev; xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen); char *atom_name; xcb_intern_atom_cookie_t atom_systray_q; xcb_intern_atom_reply_t *atom_systray_r; xcb_atom_t atom_systray; /* Send requests */ if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen))) { warn("error getting systray atom"); return; } atom_systray_q = xcb_intern_atom_unchecked(globalconf.connection, false, a_strlen(atom_name), atom_name); p_delete(&atom_name); globalconf.screens[phys_screen].systray.window = xcb_generate_id(globalconf.connection); xcb_create_window(globalconf.connection, xscreen->root_depth, globalconf.screens[phys_screen].systray.window, xscreen->root, -1, -1, 1, 1, 0, XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL); /* Fill event */ p_clear(&ev, 1); ev.response_type = XCB_CLIENT_MESSAGE; ev.window = xscreen->root; ev.format = 32; ev.type = MANAGER; ev.data.data32[0] = XCB_CURRENT_TIME; ev.data.data32[2] = globalconf.screens[phys_screen].systray.window; ev.data.data32[3] = ev.data.data32[4] = 0; if(!(atom_systray_r = xcb_intern_atom_reply(globalconf.connection, atom_systray_q, NULL))) { warn("error getting systray atom"); return; } ev.data.data32[1] = atom_systray = atom_systray_r->atom; p_delete(&atom_systray_r); xcb_set_selection_owner(globalconf.connection, globalconf.screens[phys_screen].systray.window, atom_systray, XCB_CURRENT_TIME); xcb_send_event(globalconf.connection, false, xscreen->root, 0xFFFFFF, (char *) &ev); }
/** Initialize systray information in X. * \param phys_screen Physical screen. */ void systray_init(int phys_screen) { xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen); globalconf.screens.tab[phys_screen].systray.window = xcb_generate_id(globalconf.connection); xcb_create_window(globalconf.connection, xscreen->root_depth, globalconf.screens.tab[phys_screen].systray.window, xscreen->root, -1, -1, 1, 1, 0, XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL); }
void createWindow() { eventmask = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_KEY_RELEASE; uint32_t valuelist[] = { eventmask, colormap }; uint32_t valuemask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; xcb_create_window( connection, XCB_COPY_FROM_PARENT, window, screen->root, 0, 0, width, height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, visualID, valuemask, valuelist); // NOTE: window must be mapped before glXMakeContextCurrent xcb_map_window(connection, window); // Create GLX Window glxwindow = glXCreateWindow(display, fb_config, window, 0); if (!glxwindow) printf("glXCreateWindow failed"); drawable = glxwindow; // make OpenGL context current if (!glXMakeContextCurrent(display, drawable, drawable, context)) printf("glXMakeContextCurrent failed"); // Set swap interval #ifdef NVIDIA_GL PFNGLXSWAPINTERVALSGIPROC glXSwapInterval = reinterpret_cast<PFNGLXSWAPINTERVALSGIPROC> (glXGetProcAddress( reinterpret_cast<GLubyte const *>("glXSwapIntervalSGI"))); if (!glXSwapInterval) { printf("VSync is not supported"); } else { glXSwapInterval(1); } #endif setWindowTitle(programTile); }
/** Initialize systray information in X. */ void systray_init(void) { xcb_screen_t *xscreen = globalconf.screen; globalconf.systray.window = xcb_generate_id(globalconf.connection); xcb_create_window(globalconf.connection, xscreen->root_depth, globalconf.systray.window, xscreen->root, -1, -1, 1, 1, 0, XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL); }
bool Window::Create( const char *title ) { int screen_index; Parameters.Connection = xcb_connect( nullptr, &screen_index ); if( !Parameters.Connection ) { return false; } const xcb_setup_t *setup = xcb_get_setup( Parameters.Connection ); xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator( setup ); while( screen_index-- > 0 ) { xcb_screen_next( &screen_iterator ); } xcb_screen_t *screen = screen_iterator.data; Parameters.Handle = xcb_generate_id( Parameters.Connection ); uint32_t value_list[] = { screen->white_pixel, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY }; xcb_create_window( Parameters.Connection, XCB_COPY_FROM_PARENT, Parameters.Handle, screen->root, 20, 20, 500, 500, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, value_list ); xcb_change_property( Parameters.Connection, XCB_PROP_MODE_REPLACE, Parameters.Handle, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen( title ), title ); return true; }
XCBWindow::XCBWindow(const WindowCreationDescriptor& creationInfo) : m_connection() , m_handle() , m_deleteWindowReply(nullptr) { int screen_index; m_connection = xcb_connect(nullptr, &screen_index); Assert(m_connection != nullptr); const xcb_setup_t* setup = xcb_get_setup(m_connection); xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator(setup); while (screen_index-- > 0) xcb_screen_next(&screen_iterator); m_screen = screen_iterator.data; Assert(m_screen != nullptr); m_handle = xcb_generate_id(m_connection); uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; uint32_t value_list[] = {m_screen->white_pixel, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY}; xcb_create_window(m_connection, XCB_COPY_FROM_PARENT, m_handle, m_screen->root, 0, 0, creationInfo.width, creationInfo.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, m_screen->root_visual, mask, value_list); xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, m_handle, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, std::strlen(creationInfo.title), creationInfo.title); xcb_flush(m_connection); Assert(xcb_connection_has_error(m_connection) == 0); }
int main(void) { xcb_connection_t *conn; xcb_screen_t *root; xcb_window_t window; uint32_t mask; uint32_t values[5]; xcb_generic_event_t *event; struct xamine_context *ctx; struct xamine_conversation *conversation; conn = xcb_connect(NULL, NULL); root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; window = xcb_generate_id(conn); mask = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_BACKING_STORE | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK; values[0] = root->white_pixel; values[1] = root->black_pixel; values[2] = XCB_BACKING_STORE_ALWAYS; values[3] = 0; values[4] = AllEventsMask; xcb_create_window(conn, 0, window, root->root, 0, 0, 256, 256, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, root->root_visual, mask, values); xcb_map_window(conn, window); xcb_flush(conn); ctx = xamine_context_new(0); conversation = xamine_conversation_new(ctx, 0); while ((event = xcb_wait_for_event(conn)) != NULL) { struct xamine_item *item = xamine_examine(conversation, XAMINE_RESPONSE, event, 32); free(event); print_tree(item, 0); /* Exit on ESC. */ if (strcmp(item->definition->name, "KeyPress") == 0 && item->child->next->u.unsigned_value == 9) { xamine_item_free(item); break; } xamine_item_free(item); } xamine_conversation_unref(conversation); xamine_context_unref(ctx); xcb_disconnect(conn); xmlCleanupParser(); return 0; }
/** Initialize a simple window. * \param sw The simple window to initialize. * \param phys_screen Physical screen number. * \param geometry Window geometry. * \param border_width Window border width. * \param orientation The rendering orientation. * \param bg Default foreground color. * \param bg Default background color. */ void simplewindow_init(simple_window_t *sw, int phys_screen, area_t geometry, uint16_t border_width, orientation_t orientation, const xcolor_t *fg, const xcolor_t *bg) { xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen); uint32_t create_win_val[3]; const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND; const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel }; sw->geometry.x = geometry.x; sw->geometry.y = geometry.y; sw->geometry.width = geometry.width; sw->geometry.height = geometry.height; sw->border.width = border_width; sw->orientation = orientation; sw->ctx.fg = *fg; sw->ctx.bg = *bg; create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE; create_win_val[1] = 1; create_win_val[2] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE; sw->window = xcb_generate_id(globalconf.connection); xcb_create_window(globalconf.connection, s->root_depth, sw->window, s->root, geometry.x, geometry.y, geometry.width, geometry.height, border_width, XCB_COPY_FROM_PARENT, s->root_visual, XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, create_win_val); sw->pixmap = xcb_generate_id(globalconf.connection); xcb_create_pixmap(globalconf.connection, s->root_depth, sw->pixmap, s->root, geometry.width, geometry.height); sw->ctx.phys_screen = phys_screen; simplewindow_draw_context_update(sw, s); /* The default GC is just a newly created associated to the root window */ sw->gc = xcb_generate_id(globalconf.connection); xcb_create_gc(globalconf.connection, sw->gc, s->root, gc_mask, gc_values); }
/* * Opens the window we use for input/output and maps it * */ xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height) { xcb_window_t win = xcb_generate_id(conn); //xcb_cursor_t cursor_id = xcb_generate_id(conn); #if 0 /* Use the default cursor (left pointer) */ if (cursor > -1) { i3Font *cursor_font = load_font(conn, "cursor"); xcb_create_glyph_cursor(conn, cursor_id, cursor_font->id, cursor_font->id, XCB_CURSOR_LEFT_PTR, XCB_CURSOR_LEFT_PTR + 1, 0, 0, 0, 65535, 65535, 65535); } #endif uint32_t mask = 0; uint32_t values[3]; mask |= XCB_CW_BACK_PIXEL; values[0] = 0; mask |= XCB_CW_OVERRIDE_REDIRECT; values[1] = 1; mask |= XCB_CW_EVENT_MASK; values[2] = XCB_EVENT_MASK_EXPOSURE; xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, /* the window id */ root, /* parent == root */ 50, 50, width, height, /* dimensions */ 0, /* border = 0, we draw our own */ XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */ mask, values); #if 0 if (cursor > -1) xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id); #endif /* Map the window (= make it visible) */ xcb_map_window(conn, win); return win; }
void v_window::_initOSWindow() { int screenNumber = 0; _xcb_connection = xcb_connect(nullptr,&screenNumber); const xcb_setup_t* setup = xcb_get_setup(_xcb_connection); xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup); xcb_screen_t* screen = it.data; _xcb_window = xcb_generate_id(_xcb_connection); uint32_t value_mask, value_list[ 32 ]; int16_t x=0,y=0; value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; value_list[0] = screen->black_pixel; value_list[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY; //需要接收的事件 xcb_create_window(_xcb_connection, XCB_COPY_FROM_PARENT, _xcb_window, screen->root, x,y, _width,_height, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list); /* Magic code that will send notification when window is destroyed */ xcb_intern_atom_cookie_t cookie = xcb_intern_atom( _xcb_connection, 1, 12, "WM_PROTOCOLS" ); xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply( _xcb_connection, cookie, 0 ); xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom( _xcb_connection, 0, 16, "WM_DELETE_WINDOW" ); _xcb_atom_window_reply = xcb_intern_atom_reply( _xcb_connection, cookie2, 0 ); xcb_change_property( _xcb_connection, XCB_PROP_MODE_REPLACE, _xcb_window, ( *reply ).atom, 4, 32, 1, &( *_xcb_atom_window_reply ).atom ); free( reply ); xcb_map_window(_xcb_connection,_xcb_window); // Force the x/y coordinates to 100,100 results are identical in consecutive const uint32_t coords[] = { 100, 100 }; xcb_configure_window( _xcb_connection, _xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords ); xcb_flush(_xcb_connection); }
// Set up a window using XCB and request event types xcb_window_t VulkanExampleBase::setupWindow() { uint32_t value_mask, value_list[32]; window = xcb_generate_id(connection); value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; value_list[0] = screen->black_pixel; value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE; xcb_create_window(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0, 0, width, height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list); /* Magic code that will send notification when window is destroyed */ xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(connection, cookie, 0); xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom); std::string windowTitle = getWindowTitle(); xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, title.size(), windowTitle.c_str()); free(reply); xcb_map_window(connection, window); return(window); }
int main(void) { xcb_connection_t *dpy = xcb_connect(NULL, NULL); if (dpy == NULL) { fprintf(stderr, "Can't connect to X.\n"); return EXIT_FAILURE; } xcb_atom_t WM_PROTOCOLS, WM_DELETE_WINDOW; if (!get_atom(dpy, "WM_PROTOCOLS", &WM_PROTOCOLS) || !get_atom(dpy, "WM_DELETE_WINDOW", &WM_DELETE_WINDOW)) { fprintf(stderr, "Can't get required atoms.\n"); xcb_disconnect(dpy); return EXIT_FAILURE; } xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data; if (screen == NULL) { fprintf(stderr, "Can't get current screen.\n"); xcb_disconnect(dpy); return EXIT_FAILURE; } xcb_window_t win = xcb_generate_id(dpy); uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; uint32_t values[] = {0xff111111, XCB_EVENT_MASK_EXPOSURE}; xcb_create_window(dpy, XCB_COPY_FROM_PARENT, win, screen->root, 0, 0, 320, 240, 2, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, values); xcb_icccm_set_wm_class(dpy, win, sizeof(TEST_WINDOW_IC), TEST_WINDOW_IC); xcb_map_window(dpy, win); xcb_flush(dpy); xcb_generic_event_t *evt; bool running = true; while (running && (evt = xcb_wait_for_event(dpy)) != NULL) { uint8_t rt = XCB_EVENT_RESPONSE_TYPE(evt); if (rt == XCB_CLIENT_MESSAGE) { xcb_client_message_event_t *cme = (xcb_client_message_event_t *) evt; if (cme->type == WM_PROTOCOLS && cme->data.data32[0] == WM_DELETE_WINDOW) { running = false; } } else if (rt == XCB_EXPOSE) { render_text(dpy, win, 12, 24); } free(evt); } xcb_destroy_window(dpy, win); xcb_disconnect(dpy); return EXIT_SUCCESS; }
static xcb_window_t create_window(xcb_connection_t * connection, xcb_screen_t * screen) { xcb_window_t window = xcb_generate_id(connection); uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT; uint32_t values[2] = { 0xffff0000, 1 }; xcb_create_window(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); return window; }
void NGBCreateWindow() { xcb_create_window(con, XCB_COPY_FROM_PARENT, win, screen->root, 0, 0, 640, 480, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); xcb_map_window(con, win); xcb_flush(con); }
int main() { xcb_connection_t *conn = xcb_connect(NULL, NULL); xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; xcb_drawable_t win = screen->root; xcb_gcontext_t fg = xcb_generate_id(conn); uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; uint32_t values[2] = { screen->black_pixel, 0 }; xcb_create_gc(conn, fg, win, mask, values); win = xcb_generate_id(conn); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS; xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, screen->root, x, y, w, h, bw, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); xcb_map_window(conn, win); xcb_flush(conn); xcb_generic_event_t *event; // xcb_poll_for_event does not block, so this will only catch the EXPOSE event then die out. // If we used xcb_wait_for_event, we'd block, thus continuing the loop and would actually // have a window to receive a possible XCB_BUTTON_PRESS. while ((event = xcb_wait_for_event(conn))) { switch (event->response_type & ~0x80) { case XCB_EXPOSE: printf("Expose event\n"); xcb_flush(conn); break; case XCB_BUTTON_PRESS: printf("Button press\n"); xcb_flush(conn); break; default: printf("Some otherrr event\n"); break; } free(event); } return 0; }
monitor_t *make_monitor(xcb_rectangle_t rect) { monitor_t *m = malloc(sizeof(monitor_t)); snprintf(m->name, sizeof(m->name), "%s%02d", DEFAULT_MON_NAME, ++monitor_uid); m->prev = m->next = NULL; m->desk = m->desk_head = m->desk_tail = NULL; m->rectangle = rect; m->top_padding = m->right_padding = m->bottom_padding = m->left_padding = 0; m->wired = true; m->num_sticky = 0; uint32_t mask = XCB_CW_EVENT_MASK; uint32_t values[] = {XCB_EVENT_MASK_ENTER_WINDOW}; m->root = xcb_generate_id(dpy); xcb_create_window(dpy, XCB_COPY_FROM_PARENT, m->root, root, rect.x, rect.y, rect.width, rect.height, 0, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_COPY_FROM_PARENT, mask, values); window_lower(m->root); if (focus_follows_pointer) window_show(m->root); return m; }
EGLNativeWindowType QEglFSX11Hooks::createNativeWindow(QPlatformWindow *platformWindow, const QSize &size, const QSurfaceFormat &format) { Q_UNUSED(format); m_platformWindow = platformWindow; xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(m_connection)); m_window = xcb_generate_id(m_connection); xcb_create_window(m_connection, XCB_COPY_FROM_PARENT, m_window, it.data->root, 0, 0, size.width(), size.height(), 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, it.data->root_visual, 0, 0); xcb_map_window(m_connection, m_window); xcb_intern_atom_cookie_t cookies[Atoms::N_ATOMS]; static const char *atomNames[Atoms::N_ATOMS] = { "_NET_WM_NAME", "UTF8_STRING", "WM_PROTOCOLS", "WM_DELETE_WINDOW", "_NET_WM_STATE", "_NET_WM_STATE_FULLSCREEN" }; for (int i = 0; i < Atoms::N_ATOMS; ++i) { cookies[i] = xcb_intern_atom(m_connection, false, strlen(atomNames[i]), atomNames[i]); xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(m_connection, cookies[i], 0); m_atoms[i] = reply->atom; free(reply); } // Set window title xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, m_window, m_atoms[Atoms::_NET_WM_NAME], m_atoms[Atoms::UTF8_STRING], 8, 5, "EGLFS"); // Enable WM_DELETE_WINDOW xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, m_window, m_atoms[Atoms::WM_PROTOCOLS], XCB_ATOM_ATOM, 32, 1, &m_atoms[Atoms::WM_DELETE_WINDOW]); if (qgetenv("EGLFS_X11_FULLSCREEN").toInt()) { // Go fullscreen. The QScreen and QWindow size is controlled by EGLFS_X11_SIZE regardless, // this is just the native window. xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, m_window, m_atoms[Atoms::_NET_WM_STATE], XCB_ATOM_ATOM, 32, 1, &m_atoms[Atoms::_NET_WM_STATE_FULLSCREEN]); } xcb_flush(m_connection); return m_window; }