Client *Client::manage(xcb_window_t window, int screenNumber) { assert(sClients.count(window) == 0); Client *ptr = new Client(window); ptr->mScreenNumber = screenNumber; ptr->init(); WindowManager *wm = WindowManager::instance(); wm->js().onClient(ptr); xcb_ewmh_connection_t* ewmhConn = wm->ewmhConnection(); bool focus = false; if (!ptr->mEwmhState.contains(ewmhConn->_NET_WM_STATE_STICKY)) { Workspace *ws = wm->activeWorkspace(screenNumber); assert(ws); ptr->mWorkspace = ws; ws->addClient(ptr); focus = true; } ptr->complete(); if (focus) ptr->focus(); sClients[window] = ptr; return ptr; }
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; }