//=========================================== // Lumina-DE source code // Copyright (c) 2014, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "LuminaX11.h" #include #include #include #include #include //X includes (these need to be last due to Qt compile issues) #include #include #include #include #include //XCB Library includes #include #include #include #include #include #include #include #include #define DEBUG 0 //===== WindowList() ======== QList LX11::WindowList(){ QList output; output << LX11::GetClientList(); //Validate windows int desk = LX11::GetCurrentDesktop(); for(int i=0; i= 0 && LX11::WindowDesktop(output[i]) != desk){ remove = true; } else if( name=="Lumina Desktop Environment" ){ remove = true; } else if(name.startsWith("Lumina-")){ //qDebug() << "Lumina Window:" << name << LX11::WindowName(output[i]); if(LX11::WindowName(output[i]).toLower()==name.toLower() ){ remove=true; } } /*else if( name.isEmpty() ){ qDebug() << "Abnormal Window:" << output[i]; qDebug() << " - Class:" << name; qDebug() << " - Text:" << LX11::WindowName(output[i]); qDebug() << " - Visible Name:" << LX11::WindowVisibleName(output[i]); qDebug() << " - Icon Name:" << LX11::WindowIconName(output[i]); }*/ if(remove){ //qDebug() << "Skip Window:" << output[i]; output.removeAt(i); i--; } } //qDebug() << output; //Return the list return output; } // ===== GetClientList() ===== QList LX11::GetClientList(){ QList output; //XCB Library /*qDebug() << "Get Client list cookie"; xcb_get_property_cookie_t cookie = xcb_ewmh_get_client_list_unchecked( LX11::EWMH_C(), 0); xcb_ewmh_get_windows_reply_t winlist; qDebug() << "Get client list"; if( xcb_ewmh_get_client_list_reply( LX11::EWMH_C(), cookie, &winlist, NULL) ){ qDebug() << " - Loop over items"; for(unsigned int i=0; i= Success) && (num > 0) ){ Window* array = (Window*) data; for(unsigned int i=0; i LX11::GetClientStackingList(){ QList output; Atom a = XInternAtom(QX11Info::display(), "_NET_CLIENT_LIST_STACKING", true); Atom realType; int format; unsigned long num, bytes; unsigned char *data = 0; int status = XGetWindowProperty(QX11Info::display(), QX11Info::appRootWindow(), a, 0L, (~0L), false, AnyPropertyType, &realType, &format, &num, &bytes, &data); if( (status >= Success) && (num > 0) ){ Window* array = (Window*) data; for(unsigned int i=0; i LX11::findChildren(WId parent, int levels){ Window rootR, parentR; Window *childrenR; unsigned int num; int stat = XQueryTree(QX11Info::display(), parent, &rootR, &parentR, &childrenR, &num); QList output; if(stat != 0 && num > 0){ for(int i=0; i 0){ output << LX11::findChildren(childrenR[i], levels-1); //call this recursively } } XFree(childrenR); } return output; } // ===== ActiveWindow() ===== WId LX11::ActiveWindow(){ Display *disp = QX11Info::display(); Atom SA = XInternAtom(disp, "_NET_ACTIVE_WINDOW", false); Atom type; int format; unsigned long num, bytes; unsigned char *data = 0; int status = XGetWindowProperty( disp, QX11Info::appRootWindow() , SA, 0, ~(0L), false, AnyPropertyType, &type, &format, &num, &bytes, &data); WId window=0; if(status >= Success && data){ Window *array = (Window*) data; window = array[0]; XFree(data); } return window; } // ===== SetNumberOfDesktops() ===== void LX11::SetNumberOfDesktops(int number){ //XCB Library //XLib Display *display = QX11Info::display(); Window rootWindow = QX11Info::appRootWindow(); Atom atom = XInternAtom(display, "_NET_NUMBER_OF_DESKTOPS", False); XEvent xevent; xevent.type = ClientMessage; xevent.xclient.type = ClientMessage; xevent.xclient.display = display; xevent.xclient.window = rootWindow; xevent.xclient.message_type = atom; xevent.xclient.format = 32; xevent.xclient.data.l[0] = number; xevent.xclient.data.l[1] = CurrentTime; xevent.xclient.data.l[2] = 0; xevent.xclient.data.l[3] = 0; xevent.xclient.data.l[4] = 0; XSendEvent(display, rootWindow, False, SubstructureNotifyMask | SubstructureRedirectMask, &xevent); XFlush(display); } // ===== SetCurrentDesktop() ===== void LX11::SetCurrentDesktop(int number){ Display *display = QX11Info::display(); Window rootWindow = QX11Info::appRootWindow(); Atom atom = XInternAtom(display, "_NET_CURRENT_DESKTOP", False); XEvent xevent; xevent.type = ClientMessage; xevent.xclient.type = ClientMessage; xevent.xclient.display = display; xevent.xclient.window = rootWindow; xevent.xclient.message_type = atom; xevent.xclient.format = 32; xevent.xclient.data.l[0] = number; xevent.xclient.data.l[1] = CurrentTime; xevent.xclient.data.l[2] = 0; xevent.xclient.data.l[3] = 0; xevent.xclient.data.l[4] = 0; XSendEvent(display, rootWindow, False, SubstructureNotifyMask | SubstructureRedirectMask, &xevent); XFlush(display); } // ===== GetNumberOfDesktops() ===== int LX11::GetNumberOfDesktops(){ int number = -1; Atom a = XInternAtom(QX11Info::display(), "_NET_NUMBER_OF_DESKTOPS", true); Atom realType; int format; unsigned long num, bytes; unsigned char *data = 0; int status = XGetWindowProperty(QX11Info::display(), QX11Info::appRootWindow(), a, 0L, (~0L), false, AnyPropertyType, &realType, &format, &num, &bytes, &data); if( (status >= Success) && (num > 0) ){ number = *data; XFree(data); } return number; } // ===== GetCurrentDesktop ===== int LX11::GetCurrentDesktop(){ int number = -1; Atom a = XInternAtom(QX11Info::display(), "_NET_CURRENT_DESKTOP", true); Atom realType; int format; unsigned long num, bytes; unsigned char *data = 0; int status = XGetWindowProperty(QX11Info::display(), QX11Info::appRootWindow(), a, 0L, (~0L), false, AnyPropertyType, &realType, &format, &num, &bytes, &data); if( (status >= Success) && (num > 0) ){ number = data[0]; XFree(data); } return number; } // ===== ValidWindowEvent() ===== /*bool LX11::ValidWindowEvent(Atom evAtom){ if(evAtom == XInternAtom(QX11Info::display(),"_NET_CLIENT_LIST",false) ){ return true; } else if( evAtom == XInternAtom(QX11Info::display(),"_NET_ACTIVE_WINDOW",false) ){ return true; } else if( evAtom == XInternAtom(QX11Info::display(),"_NET_WM_NAME",false) ){ return true; } else if( evAtom == XInternAtom(QX11Info::display(),"_NET_WM_VISIBLE_NAME",false) ){ return true; } else if( evAtom == XInternAtom(QX11Info::display(),"_NET_WM_ICON_NAME",false) ){ return true; } else if( evAtom == XInternAtom(QX11Info::display(),"_NET_WM_VISIBLE_ICON_NAME",false) ){ return true; } else{ return false; } }*/ // ===== CloseWindow() ===== void LX11::CloseWindow(WId win){ Display *display = QX11Info::display(); Window rootWindow = QX11Info::appRootWindow(); Atom atom = XInternAtom(display, "_NET_CLOSE_WINDOW", False); XEvent xevent; xevent.type = ClientMessage; xevent.xclient.type = ClientMessage; xevent.xclient.display = display; xevent.xclient.window = win; xevent.xclient.message_type = atom; xevent.xclient.format = 32; xevent.xclient.data.l[0] = CurrentTime; xevent.xclient.data.l[1] = 2; xevent.xclient.data.l[2] = 0; xevent.xclient.data.l[3] = 0; xevent.xclient.data.l[4] = 0; XSendEvent(display, rootWindow, False, SubstructureNotifyMask | SubstructureRedirectMask, &xevent); XFlush(display); } void LX11::KillWindow(WId win){ XKillClient(QX11Info::display(),win); } // ===== IconifyWindow() ===== void LX11::IconifyWindow(WId win){ XIconifyWindow(QX11Info::display(), win, QX11Info::appScreen()); } // ===== RestoreWindow() ===== void LX11::RestoreWindow(WId win){ //XCB Library uint32_t val = XCB_STACK_MODE_ABOVE; xcb_configure_window(QX11Info::connection(), win, XCB_CONFIG_WINDOW_STACK_MODE, &val); //raise it xcb_map_window(QX11Info::connection(), win); //map it //XLib //Display *disp = QX11Info::display(); //XMapRaised(disp, win); //make it visible again and raise it to the top } // ===== ActivateWindow() ===== void LX11::ActivateWindow(WId win){ Display *display = QX11Info::display(); Window rootWindow = QX11Info::appRootWindow(); Atom atom = XInternAtom(display, "_NET_ACTIVE_WINDOW", False); XEvent xevent; xevent.type = ClientMessage; xevent.xclient.type = ClientMessage; xevent.xclient.display = display; xevent.xclient.window = win; xevent.xclient.message_type = atom; xevent.xclient.format = 32; xevent.xclient.data.l[0] = 2; xevent.xclient.data.l[1] = CurrentTime; xevent.xclient.data.l[2] = LX11::ActiveWindow(); xevent.xclient.data.l[3] = 0; xevent.xclient.data.l[4] = 0; XSendEvent(display, rootWindow, False, SubstructureNotifyMask | SubstructureRedirectMask, &xevent); XFlush(display); } // ===== ReservePanelLocation() ===== void LX11::ReservePanelLocation(WId win, int xstart, int ystart, int width, int height, QString loc){ unsigned long strut[12]; for(int i=0; i<12; i++){ strut[i] = 0; } //initialize it to all zeros if(loc=="top"){ //top of screen strut[2] = height; //top width strut[8] = xstart; //top x start strut[9] = xstart+width; //top x end }else if(loc=="bottom"){ //bottom of screen strut[3] = height; //bottom width strut[10] = xstart; //bottom x start strut[11] = xstart+width; //bottom x end }else if(loc=="left"){ strut[0] = width; strut[4]=ystart; strut[5]=ystart+height; }else{ //right strut[1] = width; strut[6]=ystart; strut[7]=ystart+height; } Display *disp = QX11Info::display(); Atom WTYPE = XInternAtom(disp, "_NET_WM_STRUT_PARTIAL", false); XChangeProperty( disp, win, WTYPE, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) strut, 12); //Also set the _NET_WM_STRUT property, just in case the WM does not use the newer type WTYPE = XInternAtom(disp, "_NET_WM_STRUT", false); XChangeProperty( disp, win, WTYPE, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) strut, 4); } // ===== SetAsSticky() ===== void LX11::SetAsSticky(WId win){ //make this window "stick" to all virtual desktops //XCB Library // xcb_change_property(QX11Info::connection(), XCB_PROP_MODE_APPEND, win, _NET_WM_STATE, XCB_ATOM, 32, 1, _NET_WM_STATE_STICKY); //XLib Display *disp = QX11Info::display(); Atom stick = XInternAtom(disp, "_NET_WM_STATE_STICKY",false); Atom state = XInternAtom(disp, "_NET_WM_STATE", false); XChangeProperty(disp, win, state, XA_ATOM, 32, PropModeAppend, (unsigned char*) &stick, 1L); } // ===== SetAsPanel() ===== void LX11::SetAsPanel(WId win){ //Set this window as the "Dock" type (for showing on top of everthing else) long data[1]; Display *disp = QX11Info::display(); Atom WTYPE = XInternAtom(disp, "_NET_WM_WINDOW_TYPE", false); Atom DOCK = XInternAtom(disp, "_NET_WM_WINDOW_TYPE_DOCK",false); data[0] = DOCK; XChangeProperty( disp, win, WTYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &data, 1L); } // ===== SetAsDesktop() ===== void LX11::SetAsDesktop(WId win){ //Set this window as the "Desktop" type (for showing below everthing else) long data[1]; Display *disp = QX11Info::display(); Atom WTYPE = XInternAtom(disp, "_NET_WM_WINDOW_TYPE", false); Atom DOCK = XInternAtom(disp, "_NET_WM_WINDOW_TYPE_DESKTOP",false); data[0] = DOCK; XChangeProperty( disp, win, WTYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &data, 1L); } // ===== MoveResizeWindow() ===== void LX11::MoveResizeWindow(WId win, QRect rect){ //Note: rect needs to be in global coordinates!! XMoveResizeWindow(QX11Info::display(), win, rect.x(), rect.y(), rect.width(), rect.height()); } // ===== ResizeWindow() ===== void LX11::ResizeWindow(WId win, int width, int height){ XResizeWindow(QX11Info::display(), win, width, height); } // ===== CreateWindow() ===== WId LX11::CreateWindow(WId parent, QRect rect){ if(parent==0){ parent = QX11Info::appRootWindow(); } XWindowAttributes patt; XSetWindowAttributes att; att.background_pixel=0; att.border_pixel=0; //Try to set the same attributes as the parent if( ! XGetWindowAttributes(QX11Info::display(), parent, &patt) ){ //Use some simple defaults instead att.colormap = None; }else{ att.colormap = patt.colormap; } return XCreateWindow( QX11Info::display(), parent, rect.x(), rect.y(), rect.width(), rect.height(), 0, CopyFromParent, InputOutput, CopyFromParent, CWColormap|CWBackPixel|CWBorderPixel, &att); } // ===== DestroyWindow() ===== void LX11::DestroyWindow(WId win){ XDestroyWindow( QX11Info::display(), win); } // ===== EmbedWindow() ===== bool LX11::EmbedWindow(WId win, WId container){ Display *disp = QX11Info::display(); if(win==0 || container==0){ return false; } //Reparent the window //XCompositeRedirectSubwindows(disp, container, CompositeRedirectAutomatic); //container/window should be aware of each other //qDebug() << "Embed Window:" << win << container; XReparentWindow(disp, win, container,0,0); XSync(disp, false); //Map the window XMapRaised(disp, win); //make it visible again and raise it to the top //Check that the window has _XEMBED_INFO //qDebug() << " - check for _XEMBED_INFO"; Atom embinfo = XInternAtom(disp, "_XEMBED_INFO",false); uchar *data=0; ulong num, bytes; int fmt; Atom junk; if(Success != XGetWindowProperty(disp, win, embinfo, 0, 2, false, embinfo, &junk, &fmt, &num, &bytes, &data) ){ return false; //Embedding error (no info?) } if(data){ XFree(data); } // clean up any data found //Now send the embed event to the app //qDebug() << " - send _XEMBED event"; XEvent ev; ev.xclient.type=ClientMessage; ev.xclient.serial=0; ev.xclient.send_event=true; ev.xclient.message_type = XInternAtom(disp, "_XEMBED", false); ev.xclient.window = win; ev.xclient.format = 32; ev.xclient.data.l[0] = CurrentTime; ev.xclient.data.l[1] = 0; //XEMBED_EMBEDDED_NOTIFY ev.xclient.data.l[2] = 0; ev.xclient.data.l[3] = container; ev.xclient.data.l[4] = 0; XSendEvent(disp, win, false, 0xFFFFFF, &ev); //Now setup any redirects and return //qDebug() << " - select Input"; XSelectInput(disp, win, StructureNotifyMask); //Notify of structure changes //qDebug() << " - Composite Redirect"; XCompositeRedirectWindow(disp, win, CompositeRedirectManual); //qDebug() << " - Done"; return true; } // ===== UnembedWindow() ===== bool LX11::UnembedWindow(WId win){ Display *disp = QX11Info::display(); //Remove redirects XSelectInput(disp, win, NoEventMask); //Make sure it is invisible XUnmapWindow(disp, win); //Reparent the window back to the root window XReparentWindow(disp, win, QX11Info::appRootWindow(),0,0); XSync(disp, false); return true; } // ===== WindowClass() ===== QString LX11::WindowClass(WId win){ XClassHint hint; QString clss; if(0 != XGetClassHint(QX11Info::display(), win, &hint) ){ clss = QString(hint.res_class); //class is often capitalized properly, while name is not XFree(hint.res_name); XFree(hint.res_class); } return clss; } // ===== WindowName() ===== QString LX11::WindowName(WId win){ QString nm = LX11::getNetWMProp(win, "_NET_WM_NAME"); if(nm.isEmpty()){ char *txt; if( XFetchName(QX11Info::display(), win, &txt) != 0){ nm = QString(txt); } XFree(txt); } return nm; } // ===== WindowVisibleName() ===== QString LX11::WindowVisibleName(WId win){ return LX11::getNetWMProp(win, "_NET_WM_VISIBLE_NAME"); } // ===== WindowIconName() ===== QString LX11::WindowIconName(WId win){ return LX11::getNetWMProp(win, "_NET_WM_ICON_NAME"); } // ===== WindowVisibleIconName() ===== QString LX11::WindowVisibleIconName(WId win){ return LX11::getNetWMProp(win, "_NET_WM_VISIBLE_ICON_NAME"); } // ===== WindowIcon() ===== /*QIcon LX11::WindowIcon(WId win){ //Use the _NET_WM_ICON value instead of the WMHints pixmaps // - the pixmaps are very unstable and erratic QIcon icon; Display *disp = QX11Info::display(); Atom type; Atom SA = XInternAtom(disp, "_NET_WM_ICON", false); int format; unsigned long num, bytes; unsigned long *data = 0; XGetWindowProperty( disp, win, SA, 0, LONG_MAX, False, AnyPropertyType, &type, &format, &num, &bytes, (uchar**)&data); if(data != 0){ //qDebug() << "Icon Data Found:" << win; ulong* dat = data; while(dat < data+num){ //consider the fact that there may be multiple graphical layers //Now convert it into a Qt image // - first 2 elements are width and height // - data in rows from left to right and top to bottom QImage image(dat[0], dat[1], QImage::Format_ARGB32); //initial setup dat+=2; //remember the first 2 element offset for(int i=0; idata, xim->width, xim->height, xim->bytes_per_line, QImage::Format_ARGB32_Premultiplied) ); XDestroyImage(xim); //clean up } //Return the pixmap return pix; }*/ // ===== GetNumberOfDesktops() ===== int LX11::WindowDesktop(WId win){ int number = -1; Atom a = XInternAtom(QX11Info::display(), "_NET_WM_DESKTOP", true); Atom realType; int format; unsigned long num, bytes; unsigned char *data = 0; int status = XGetWindowProperty(QX11Info::display(), win, a, 0L, (~0L), false, AnyPropertyType, &realType, &format, &num, &bytes, &data); if( (status >= Success) && (num > 0) ){ number = *data; XFree(data); } return number; } // ===== GetWindowState() ===== LX11::WINDOWSTATE LX11::GetWindowState(WId win){ LX11::WINDOWSTATE state = LX11::VISIBLE; //XCB Library (TO DO) //XLib Display *disp = QX11Info::display(); Atom SA = XInternAtom(disp, "_NET_WM_STATE", true); Atom ATTENTION = XInternAtom(disp, "_NET_WM_STATE_DEMANDS_ATTENTION", false); Atom SKIPP = XInternAtom(disp, "_NET_WM_STATE_SKIP_PAGER", false); Atom HIDDEN = XInternAtom(disp, "_NET_WM_STATE_HIDDEN", false); Atom SKIPT = XInternAtom(disp, "_NET_WM_STATE_SKIP_TASKBAR", false); //Atom MODAL = XInternAtom(disp, "_NET_WM_STATE_MODAL", false); Atom type; int format; unsigned long num, bytes; unsigned long *data = 0; int status = XGetWindowProperty( disp, win, SA, 0, ~(0L), false, AnyPropertyType, &type, &format, &num, &bytes, (unsigned char**) &data); if(status >= Success && data){ for(unsigned int i=0; iflags & URGENCYHINT){ qDebug() << "Found Urgent Flag:"; state = LX11::ATTENTION; } XFree(hints); } } return state; } WId LX11::leaderWindow(WId win){ //Get the client leader for this window if it has one Display *disp = QX11Info::display(); Atom SA = XInternAtom(disp, "WM_CLIENT_LEADER", false); Atom type; int format; unsigned long num, bytes; unsigned char *data = 0; WId leader = 0; int status = XGetWindowProperty( disp, win, SA, 0, ~(0L), false, AnyPropertyType, &type, &format, &num, &bytes, &data); if(status >= Success && data){ Window *array = reinterpret_cast (data); if(array!=0){ leader = array[0]; } XFree(data); } return leader; } // ===== isNormalWindow() ===== bool LX11::isNormalWindow(WId win, bool includeDialogs){ //Check to see if it is a "normal" window (as opposed to tooltips, popups, menus, etc) Display *disp = QX11Info::display(); Atom SA = XInternAtom(disp, "_NET_WM_WINDOW_TYPE", false); Atom NORMAL = XInternAtom(disp, "_NET_WM_WINDOW_TYPE_NORMAL", false); Atom DIALOG = XInternAtom(disp, "_NET_WM_WINDOW_TYPE_DIALOG", false); Atom type; int format; unsigned long num, bytes; unsigned char *data = 0; int status = XGetWindowProperty( disp, win, SA, 0, ~(0L), false, AnyPropertyType, &type, &format, &num, &bytes, &data); bool isNormal = true; //assume normal is true if unlisted (the standard use) if(status >= Success && data){ for(unsigned int i=0; iscreen = QX11Info::appScreen(); XVI->depth = 32; XVI->c_class = TrueColor; int num; XVI = XGetVisualInfo(disp, VisualScreenMask | VisualDepthMask | VisualClassMask , XVI, &num); VisualID vis = 0; if(XVI != 0){ XRenderPictFormat *fmt; for(int i=0; itype == PictTypeDirect) && (fmt->direct.alphaMask!=0) ){ vis = XVI[i].visualid; break; } } } XFree(XVI); //done with this - clean it up //Now register the visual ID if(vis!=0){ XChangeProperty(disp, LuminaSessionTrayID, XInternAtom(disp,"_NET_SYSTEM_TRAY_VISUAL",true), XA_VISUALID, 32, PropModeReplace, (unsigned char*) &vis, 1); } //Finally, send out an X event letting others know that the system tray is up and running XClientMessageEvent msg; msg.type = ClientMessage; msg.window = root; msg.message_type = XInternAtom(disp,"MANAGER",true); msg.format = 32; msg.data.l[0] = CurrentTime; msg.data.l[1] = _NET_SYSTEM_TRAY_S; msg.data.l[2] = LuminaSessionTrayID; msg.data.l[3] = 0; msg.data.l[4] = 0; XSendEvent(disp, root, False, StructureNotifyMask, (XEvent*)&msg); //Success return LuminaSessionTrayID; } // ===== closeSystemTray() ===== void LX11::closeSystemTray(WId trayID){ XDestroyWindow(QX11Info::display(), trayID); } // ===== findOrphanTrayWindows() ===== QList LX11::findOrphanTrayWindows(){ //Scan the first level of root windows and see if any of them // are tray apps waiting to be embedded Display *disp = QX11Info::display(); QList wins = LX11::findChildren(QX11Info::appRootWindow(), 0); //only go one level deep Atom embinfo = XInternAtom(disp, "_XEMBED_INFO",false); for(int i=0; i= Success && data){ property = QString::fromUtf8( (char *) data); XFree(data); } return property; } //=============================== //=============================== // XCB LIBRARY FUNCTIONS //=============================== //=============================== LXCB::LXCB(){ xcb_intern_atom_cookie_t *cookie = xcb_ewmh_init_atoms(QX11Info::connection(), &EWMH); if(!xcb_ewmh_init_atoms_replies(&EWMH, cookie, NULL) ){ qDebug() << "Error with XCB atom initializations"; }else{ qDebug() << "Number of XCB screens:" << EWMH.nb_screens; } } LXCB::~LXCB(){ xcb_ewmh_connection_wipe(&EWMH); } // === WindowList() === QList LXCB::WindowList(bool rawlist){ if(DEBUG){ qDebug() << "XCB: WindowList()" << rawlist; } QList output; //qDebug() << "Get Client list cookie"; xcb_get_property_cookie_t cookie = xcb_ewmh_get_client_list_unchecked( &EWMH, 0); xcb_ewmh_get_windows_reply_t winlist; //qDebug() << "Get client list"; if( 1 == xcb_ewmh_get_client_list_reply( &EWMH, cookie, &winlist, NULL) ){ //qDebug() << " - Loop over items"; unsigned int wkspace = CurrentWorkspace(); for(unsigned int i=0; i roots){ if(DEBUG){ qDebug() << "XCB: RegisterVirtualRoots()"; } //First convert the QList into the proper format xcb_window_t *list = new xcb_window_t[ roots.length() ]; for(int i=0; iwidth, reply->height); //make sure to use the origin point for the window //qDebug() << " - "<x << reply->y << reply->width << reply->height; free(reply); if(includeFrame){ //Need to add/include the frame extents as well (assuming the frame info is available) xcb_get_property_cookie_t cookie = xcb_ewmh_get_frame_extents_unchecked(&EWMH, win); if(cookie.sequence != 0){ xcb_ewmh_get_extents_reply_t frame; if(1== xcb_ewmh_get_frame_extents_reply(&EWMH, cookie, &frame, NULL) ){ //adjust the origin point to account for the frame geom.translate(-frame.left, -frame.top); //move to the orign point for the frame //adjust the size (include the frame sizes) geom.setWidth( geom.width() + frame.left + frame.right ); geom.setHeight( geom.height() + frame.top + frame.bottom ); } //qDebug() << " - Frame:" << frame.left << frame.right << frame.top << frame.bottom; //qDebug() << " - Modified with Frame:" << geom.x() << geom.y() << geom.width() << geom.height(); } } //Now need to convert this to absolute coordinates (not parent-relavitve) xcb_translate_coordinates_cookie_t tcookie = xcb_translate_coordinates(QX11Info::connection(), win, QX11Info::appRootWindow(), geom.x(), geom.y()); xcb_translate_coordinates_reply_t *trans = xcb_translate_coordinates_reply(QX11Info::connection(), tcookie, NULL); if(trans!=0){ //qDebug() << " - Got Translation:" << trans->dst_x << trans->dst_y; //Replace the origin point with the global position (sizing remains the same) geom.moveLeft(trans->dst_x); //adjust X coordinate (no size change) geom.moveTop(trans->dst_y); //adjust Y coordinate (no size change) free(trans); } }else{ //Need to do another catch for this situation (probably not mapped yet) } return geom; } QList LXCB::WindowFrameGeometry(WId win){ if(DEBUG){ qDebug() << "XCB: WindowFrameGeometry()"; } //Returns: [top, bottom, left, right] sizes for the frame QList geom; if(win!=0){ xcb_get_property_cookie_t cookie = xcb_ewmh_get_frame_extents_unchecked(&EWMH, win); if(cookie.sequence != 0){ xcb_ewmh_get_extents_reply_t frame; if(1== xcb_ewmh_get_frame_extents_reply(&EWMH, cookie, &frame, NULL) ){ //adjust the origin point to account for the frame geom << frame.top << frame.bottom << frame.left << frame.right; } } } if(geom.isEmpty()){ geom << 0 << 0 << 0 << 0; } return geom; } // === WindowState() === LXCB::WINDOWSTATE LXCB::WindowState(WId win){ if(DEBUG){ qDebug() << "XCB: WindowState()"; } if(win==0){ return IGNORE; } xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_state_unchecked(&EWMH, win); if(cookie.sequence == 0){ return IGNORE; } xcb_ewmh_get_atoms_reply_t states; WINDOWSTATE cstate = IGNORE; //First Check for special states (ATTENTION in particular); if( 1 == xcb_ewmh_get_wm_state_reply(&EWMH, cookie, &states, NULL) ){ for(unsigned int i=0; imap_state==XCB_MAP_STATE_VIEWABLE){ cstate = VISIBLE; } else{ cstate = INVISIBLE; } free(attr); } } return cstate; } // === WindowVisibleIconName() === QString LXCB::WindowVisibleIconName(WId win){ //_NET_WM_VISIBLE_ICON_NAME if(DEBUG){ qDebug() << "XCB: WindowVisibleIconName()"; } if(win==0){ return ""; } QString out; xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_visible_icon_name_unchecked(&EWMH, win); if(cookie.sequence == 0){ return out; } xcb_ewmh_get_utf8_strings_reply_t data; if( 1 == xcb_ewmh_get_wm_visible_icon_name_reply(&EWMH, cookie, &data, NULL) ){ out = QString::fromUtf8(data.strings, data.strings_len); } return out; } // === WindowIconName() === QString LXCB::WindowIconName(WId win){ //_NET_WM_ICON_NAME if(DEBUG){ qDebug() << "XCB: WindowIconName()"; } if(win==0){ return ""; } QString out; xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_icon_name_unchecked(&EWMH, win); if(cookie.sequence == 0){ return out; } xcb_ewmh_get_utf8_strings_reply_t data; if( 1 == xcb_ewmh_get_wm_icon_name_reply(&EWMH, cookie, &data, NULL) ){ out = QString::fromUtf8(data.strings, data.strings_len); } return out; } // === WindowVisibleName() === QString LXCB::WindowVisibleName(WId win){ //_NET_WM_VISIBLE_NAME if(DEBUG){ qDebug() << "XCB: WindowVisibleName()"; } if(win==0){ return ""; } QString out; xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_visible_name_unchecked(&EWMH, win); if(cookie.sequence == 0){ return out; } xcb_ewmh_get_utf8_strings_reply_t data; if( 1 == xcb_ewmh_get_wm_visible_name_reply(&EWMH, cookie, &data, NULL) ){ out = QString::fromUtf8(data.strings, data.strings_len); } return out; } // === WindowName() === QString LXCB::WindowName(WId win){ //_NET_WM_NAME if(DEBUG){ qDebug() << "XCB: WindowName()"; } if(win==0){ return ""; } QString out; xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_name_unchecked(&EWMH, win); if(cookie.sequence == 0){ return out; } xcb_ewmh_get_utf8_strings_reply_t data; if( 1 == xcb_ewmh_get_wm_name_reply(&EWMH, cookie, &data, NULL) ){ out = QString::fromUtf8(data.strings, data.strings_len); } return out; } // === OldWindowName() === QString LXCB::OldWindowName(WId win){ //WM_NAME (old standard) if(DEBUG){ qDebug() << "XCB: OldWindowName()"; } if(win==0){ return ""; } xcb_get_property_cookie_t cookie = xcb_icccm_get_wm_name_unchecked(QX11Info::connection(), win); xcb_icccm_get_text_property_reply_t reply; if(1 == xcb_icccm_get_wm_name_reply(QX11Info::connection(), cookie, &reply, NULL) ){ QString name = QString::fromLocal8Bit(reply.name); xcb_icccm_get_text_property_reply_wipe(&reply); return name; }else{ return ""; } } // === OldWindowIconName() === QString LXCB::OldWindowIconName(WId win){ //WM_ICON_NAME (old standard) if(DEBUG){ qDebug() << "XCB: OldWindowIconName()"; } if(win==0){ return ""; } xcb_get_property_cookie_t cookie = xcb_icccm_get_wm_icon_name_unchecked(QX11Info::connection(), win); xcb_icccm_get_text_property_reply_t reply; if(1 == xcb_icccm_get_wm_icon_name_reply(QX11Info::connection(), cookie, &reply, NULL) ){ QString name = QString::fromLocal8Bit(reply.name); xcb_icccm_get_text_property_reply_wipe(&reply); return name; }else{ return ""; } } // === WindowIsMaximized() === bool LXCB::WindowIsMaximized(WId win){ if(DEBUG){ qDebug() << "XCB: WindowIsMaximized()"; } if(win==0){ return ""; } //See if the _NET_WM_STATE_MAXIMIZED_[VERT/HORZ] flags are set on the window xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_state_unchecked(&EWMH, win); if(cookie.sequence == 0){ return false; } xcb_ewmh_get_atoms_reply_t states; if( 1 == xcb_ewmh_get_wm_state_reply(&EWMH, cookie, &states, NULL) ){ //Loop over the states for(unsigned int i=0; iatom; WM_TAKE_FOCUS = freply->atom; free(preply); free(freply); gotatoms = true; qDebug() << " -- success"; } // - - Now update the protocols for the window if(gotatoms){ //requires the atoms qDebug() << " - Get WM_PROTOCOLS"; xcb_icccm_get_wm_protocols_reply_t proto; if( 1 == xcb_icccm_get_wm_protocols_reply(QX11Info::connection(), \ xcb_icccm_get_wm_protocols_unchecked(QX11Info::connection(), win, WM_PROTOCOLS), \ &proto, NULL) ){ //Found the current protocols, see if it has the focus atom set //remove the take focus atom and re-save them bool needremove = false; //Note: This first loop is required so that we can initialize the modified list with a valid size qDebug() << " -- Check current protocols"; for(unsigned int i=0; iatom; free(ereply); //done with this structure //Reparent the window into the container xcb_reparent_window(QX11Info::connection(), win, container, 0, 0); xcb_map_window(QX11Info::connection(), win); //Now send the embed event to the app //qDebug() << " - send _XEMBED event"; xcb_client_message_event_t event; event.response_type = XCB_CLIENT_MESSAGE; event.format = 32; event.window = win; event.type = emb; //_XEMBED event.data.data32[0] = CurrentTime; event.data.data32[1] = 0; //XEMBED_EMBEDDED_NOTIFY event.data.data32[2] = 0; event.data.data32[3] = container; //WID of the container event.data.data32[4] = 0; xcb_send_event(QX11Info::connection(), 0, win, XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *) &event); //Now setup any redirects and return //qDebug() << " - select Input"; //XSelectInput(disp, win, StructureNotifyMask); //Notify of structure changes uint32_t val[] = {XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY}; xcb_change_window_attributes(QX11Info::connection(), win, XCB_CW_EVENT_MASK, val); //qDebug() << " - Composite Redirect"; xcb_composite_redirect_window(QX11Info::connection(), win, XCB_COMPOSITE_REDIRECT_MANUAL); //Now map the window (will be a transparent child of the container) xcb_map_window(QX11Info::connection(), win); //Now create/register the damage handler xcb_damage_damage_t dmgID = xcb_generate_id(QX11Info::connection()); //This is a typedef for a 32-bit unsigned integer xcb_damage_create(QX11Info::connection(), dmgID, win, XCB_DAMAGE_REPORT_LEVEL_RAW_RECTANGLES); //qDebug() << " - Done"; return ( (uint) dmgID ); } // === Unembed Window() === bool LXCB::UnembedWindow(WId win){ if(DEBUG){ qDebug() << "XCB: UnembedWindow()"; } if(win==0){ return false; } //Display *disp = QX11Info::display(); //Remove redirects //XSelectInput(disp, win, NoEventMask); uint32_t val[] = {XCB_EVENT_MASK_NO_EVENT}; xcb_change_window_attributes(QX11Info::connection(), win, XCB_CW_EVENT_MASK, val); //Make sure it is invisible xcb_unmap_window(QX11Info::connection(), win); //Reparent the window back to the root window xcb_reparent_window(QX11Info::connection(), win, QX11Info::appRootWindow(), 0, 0); return true; } // === SetScreenWorkArea() === /*void LXCB::SetScreenWorkArea(unsigned int screen, QRect rect){ //This is only useful because Fluxbox does not set the _NET_WORKAREA root atom // This needs to be better incorporated into the new window manager later //First get the current workarea array (for all monitors/screens) xcb_get_property_cookie_t cookie = xcb_ewmh_get_workarea_unchecked(&EWMH, 0); xcb_ewmh_get_workarea_reply_t work; if(0==xcb_ewmh_get_workarea_reply(&EWMH, cookie, &work, NULL)){ return; } //Error: Could not retrieve current work areas //Save what we need only from the reply unsigned int desks = work.workarea_len; if(desks <= screen){ return; } //invalid screen to modify qDebug() << "Number of desktops/screens:" << desks; xcb_ewmh_geometry_t *dareas = work.workarea; //Adjust the work area for the input monitor/screen dareas[screen].x = rect.x(); dareas[screen].y = rect.y(); dareas[screen].width = rect.width(); dareas[screen].height = rect.height(); //Now save the array again xcb_ewmh_set_workarea(&EWMH, 0, desks, dareas); //_NET_WORKAREA //Make sure to clear that reply xcb_ewmh_get_workarea_reply_wipe(&work); }*/