void init_xinerama(void) { if (opt.xinerama && XineramaIsActive(disp)) { int major, minor, px, py, i; /* discarded */ Window dw; int di; unsigned int du; XineramaQueryVersion(disp, &major, &minor); xinerama_screens = XineramaQueryScreens(disp, &num_xinerama_screens); if (opt.xinerama_index >= 0) xinerama_screen = opt.xinerama_index; else { xinerama_screen = 0; XQueryPointer(disp, root, &dw, &dw, &px, &py, &di, &di, &du); for (i = 0; i < num_xinerama_screens; i++) { if (XY_IN_RECT(px, py, xinerama_screens[i].x_org, xinerama_screens[i].y_org, xinerama_screens[i].width, xinerama_screens[i].height)) { xinerama_screen = i; break; } } } } }
bool AugmentationEnvironment::getScreenSizes() { Display *d=XOpenDisplay(NULL); if (d) { int dummy1, dummy2; if (XineramaQueryExtension(d, &dummy1, &dummy2)) { if (XineramaIsActive(d)) { int heads=0; XineramaScreenInfo *p=XineramaQueryScreens(d, &heads); if (heads>0) { for (int x=0; x<heads; ++x) { cout << "Head " << x+1 << " of " << heads << ": " << p[x].width << "x" << p[x].height << " at " << p[x].x_org << "," << p[x].y_org << endl; screenRect.push_back(cv::Rect(p[x].x_org, p[x].y_org, p[x].width, p[x].height)); } return true; } else cout << "XineramaQueryScreens says there aren't any" << endl; XFree(p); } else cout << "Xinerama not active" << endl; } else cout << "No Xinerama extension" << endl; XCloseDisplay(d); } else cout << "Can't open display" << endl; return false; }
void init_xinerama(void) { int evbase, errbase, major, minor; rp_have_xinerama = 0; #ifdef XINERAMA if (xine_screens) XFree(xine_screens); if (!XineramaQueryExtension(dpy, &evbase, &errbase)) { return; } if (!XineramaQueryVersion(dpy, &major, &minor) != Success) { return; } if (major != 1) { fprintf (stderr, "Warning: Xinerama version %d.%d not supported\n", major, minor); return; } if (!XineramaIsActive(dpy)) { return; } xine_screens = XineramaQueryScreens(dpy, &xine_screen_count); if ((xine_screens == NULL) || (xine_screen_count < 2)) { return; } rp_have_xinerama = 1; #endif }
void create_monitors(void) { #ifdef XINERAMA struct monitor *mon; int i, nmon; if (XineramaIsActive(dpy)) { XineramaScreenInfo *xsi = XineramaQueryScreens(dpy, &nmon); mons = NULL; for (i = 0; i < nmon; i++) { mon = monitor_create(i, xsi[i].x_org, xsi[i].y_org, xsi[i].width, xsi[i].height); mons = monitor_append(mons, mon); } selmon = mons; return; } #endif /* XINERAMA */ selmon = mons = monitor_create(0, 0, 0, screen_w, screen_h); }
void _gdk_x11_screen_get_edge_monitors (GdkX11Screen *x11_screen, gint *top, gint *bottom, gint *left, gint *right) { #ifdef HAVE_XFREE_XINERAMA gint top_most_pos = HeightOfScreen (x11_screen->xscreen); gint left_most_pos = WidthOfScreen (x11_screen->xscreen); gint bottom_most_pos = 0; gint right_most_pos = 0; gint i; XineramaScreenInfo *x_monitors; int x_n_monitors; #endif *top = *bottom = *left = *right = -1; #ifdef HAVE_XFREE_XINERAMA if (!XineramaIsActive (x11_screen->xdisplay)) return; x_monitors = XineramaQueryScreens (x11_screen->xdisplay, &x_n_monitors); if (x_n_monitors <= 0 || x_monitors == NULL) { if (x_monitors) XFree (x_monitors); return; } for (i = 0; i < x_n_monitors; i++) { if (left && left_most_pos > x_monitors[i].x_org) { left_most_pos = x_monitors[i].x_org; *left = i; } if (right && right_most_pos < x_monitors[i].x_org + x_monitors[i].width) { right_most_pos = x_monitors[i].x_org + x_monitors[i].width; *right = i; } if (top && top_most_pos > x_monitors[i].y_org) { top_most_pos = x_monitors[i].y_org; *top = i; } if (bottom && bottom_most_pos < x_monitors[i].y_org + x_monitors[i].height) { bottom_most_pos = x_monitors[i].y_org + x_monitors[i].height; *bottom = i; } } XFree (x_monitors); #endif }
int_fast32_t xinerama_screen_count(Display *dpy) { int screens; if (!dpy) return 0; XFree(XineramaQueryScreens(dpy, &screens)); return screens; }
void X11Factory::getMonitorInfo( const GenericWindow &rWindow, int* p_x, int* p_y, int* p_width, int* p_height ) const { // initialize to default geometry *p_x = 0; *p_y = 0; *p_width = getScreenWidth(); *p_height = getScreenHeight(); // Use Xinerama to determine the monitor where the video // mostly resides (biggest surface) Display *pDisplay = m_pDisplay->getDisplay(); Window wnd = (Window)rWindow.getOSHandle(); Window root = DefaultRootWindow( pDisplay ); Window child_wnd; int x, y; unsigned int w, h, border, depth; XGetGeometry( pDisplay, wnd, &root, &x, &y, &w, &h, &border, &depth ); XTranslateCoordinates( pDisplay, wnd, root, 0, 0, &x, &y, &child_wnd ); int num; XineramaScreenInfo* info = XineramaQueryScreens( pDisplay, &num ); if( info ) { Region reg1 = XCreateRegion(); XRectangle rect1 = { (short)x, (short)y, (unsigned short)w, (unsigned short)h }; XUnionRectWithRegion( &rect1, reg1, reg1 ); unsigned int surface = 0; for( int i = 0; i < num; i++ ) { Region reg2 = XCreateRegion(); XRectangle rect2 = { info[i].x_org, info[i].y_org, (unsigned short)info[i].width, (unsigned short)info[i].height }; XUnionRectWithRegion( &rect2, reg2, reg2 ); Region reg = XCreateRegion(); XIntersectRegion( reg1, reg2, reg ); XRectangle rect; XClipBox( reg, &rect ); unsigned int surf = rect.width * rect.height; if( surf > surface ) { surface = surf; *p_x = info[i].x_org; *p_y = info[i].y_org; *p_width = info[i].width; *p_height = info[i].height; } XDestroyRegion( reg ); XDestroyRegion( reg2 ); } XDestroyRegion( reg1 ); XFree( info ); } }
int OS_X11::get_screen_count() const { // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return 0; int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); XFree(xsi); return count; }
int MythXDisplay::GetNumberXineramaScreens(void) { MythXLocker locker(this); int nr_xinerama_screens = 0; int event_base = 0, error_base = 0; if (XineramaQueryExtension(m_disp, &event_base, &error_base) && XineramaIsActive(m_disp)) { XFree(XineramaQueryScreens(m_disp, &nr_xinerama_screens)); } return nr_xinerama_screens; }
bool X11Factory::init() { // make sure xlib is safe-thread if( !vlc_xlib_init( VLC_OBJECT( getIntf() ) ) ) { msg_Err( getIntf(), "initializing xlib for multi-threading failed" ); return false; } // Create the X11 display m_pDisplay = new X11Display( getIntf() ); // Get the display Display *pDisplay = m_pDisplay->getDisplay(); if( pDisplay == NULL ) { // Initialization failed return false; } // Create the timer loop m_pTimerLoop = new X11TimerLoop( getIntf(), ConnectionNumber( pDisplay ) ); // Initialize the resource path char *datadir = config_GetUserDir( VLC_DATA_DIR ); m_resourcePath.push_back( (std::string)datadir + "/skins2" ); free( datadir ); m_resourcePath.push_back( (std::string)"share/skins2" ); datadir = config_GetDataDir(); m_resourcePath.push_back( (std::string)datadir + "/skins2" ); free( datadir ); // Determine the monitor geometry getDefaultGeometry( &m_screenWidth, &m_screenHeight ); // list all available monitors int num_screen; XineramaScreenInfo* info = XineramaQueryScreens( pDisplay, &num_screen ); if( info ) { msg_Dbg( getIntf(), "number of monitors detected : %i", num_screen ); for( int i = 0; i < num_screen; i++ ) msg_Dbg( getIntf(), " monitor #%i : %ix%i at +%i+%i", i, info[i].width, info[i].height, info[i].x_org, info[i].y_org ); XFree( info ); } return true; }
void HMDDeviceFactory::EnumerateDevices(EnumerateVisitor& visitor) { // For now we'll assume the Rift DK1 is attached in extended monitor mode. Ultimately we need to // use XFree86 to enumerate X11 screens in case the Rift is attached as a separate screen. We also // need to be able to read the EDID manufacturer product code to be able to differentiate between // Rift models. bool foundHMD = false; Display* display = XOpenDisplay(NULL); if (display && XineramaIsActive(display)) { int numberOfScreens; XineramaScreenInfo* screens = XineramaQueryScreens(display, &numberOfScreens); for (int i = 0; i < numberOfScreens; i++) { XineramaScreenInfo screenInfo = screens[i]; if (screenInfo.width == 1280 && screenInfo.height == 800) { String deviceName = "OVR0001"; HMDDeviceCreateDesc hmdCreateDesc(this, deviceName, i); hmdCreateDesc.SetScreenParameters(screenInfo.x_org, screenInfo.y_org, 1280, 800, 0.14976f, 0.0936f); OVR_DEBUG_LOG_TEXT(("DeviceManager - HMD Found %s - %d\n", deviceName.ToCStr(), i)); // Notify caller about detected device. This will call EnumerateAddDevice // if the this is the first time device was detected. visitor.Visit(hmdCreateDesc); foundHMD = true; break; } } XFree(screens); } // Real HMD device is not found; however, we still may have a 'fake' HMD // device created via SensorDeviceImpl::EnumerateHMDFromSensorDisplayInfo. // Need to find it and set 'Enumerated' to true to avoid Removal notification. if (!foundHMD) { Ptr<DeviceCreateDesc> hmdDevDesc = getManager()->FindDevice("", Device_HMD); if (hmdDevDesc) hmdDevDesc->Enumerated = true; } }
static XineramaScreenInfo *x11_query_screens(Display *dpy, int *num_screens) { int major, minor; if (!XineramaQueryExtension(dpy, &major, &minor)) return NULL; XineramaQueryVersion(dpy, &major, &minor); RARCH_LOG("[X11]: Xinerama version: %d.%d.\n", major, minor); if (!XineramaIsActive(dpy)) return NULL; return XineramaQueryScreens(dpy, num_screens); }
Size2 OS_X11::get_screen_size(int p_screen) const { // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return Size2i(0,0); int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); if( p_screen >= count ) return Size2i(0,0); Size2i size = Point2i(xsi[p_screen].width, xsi[p_screen].height); XFree(xsi); return size; }
static int map_output_xinerama(Display *dpy, int deviceid, const char *output_name) { const char *prefix = "HEAD-"; XineramaScreenInfo *screens = NULL; int rc = EXIT_FAILURE; int event, error; int nscreens; int head; Matrix m; if (!XineramaQueryExtension(dpy, &event, &error)) { fprintf(stderr, "Unable to set screen mapping. Xinerama extension not found\n"); goto out; } if (strlen(output_name) < strlen(prefix) + 1 || strncmp(output_name, prefix, strlen(prefix)) != 0) { fprintf(stderr, "Please specify the output name as HEAD-X," "where X is the screen number\n"); goto out; } head = output_name[strlen(prefix)] - '0'; screens = XineramaQueryScreens(dpy, &nscreens); if (nscreens == 0) { fprintf(stderr, "Xinerama failed to query screens.\n"); goto out; } else if (nscreens <= head) { fprintf(stderr, "Found %d screens, but you requested %s.\n", nscreens, output_name); goto out; } matrix_set_unity(&m); set_transformation_matrix(dpy, &m, screens[head].x_org, screens[head].y_org, screens[head].width, screens[head].height); rc = apply_matrix(dpy, deviceid, &m); out: XFree(screens); return rc; }
void enumDisplayMonitors(DeviceInfo displays[], int& displayCounter) { ::Display* dpy = XOpenDisplay(NULL); if (dpy == NULL) { fatalError("Could not open display"); return; } int eventBase; int errorBase; if (XineramaQueryExtension(dpy, &eventBase, &errorBase)) { if (XineramaIsActive(dpy)) { int heads = 0; XineramaScreenInfo* queried = XineramaQueryScreens(dpy, &heads); for (int head = 0; head < heads; ++head) { ++displayCounter; XineramaScreenInfo& info = queried[head]; //log(Info, "Head %i: %ix%i @%i;%i", head + 1, info.width, info.height, info.x_org, info.y_org); DeviceInfo& di = displays[displayCounter]; di.isAvailable = true; di.x = info.x_org; di.y = info.y_org; di.width = info.width; di.height = info.height; // TODO (DK) // -is this always correct? if i switch screens on deb8/jessie with gnome it works ok // -what about other *nix or window managers? di.isPrimary = displayCounter == 0; // TODO (DK) // -this doesn't work yet, whatever is configured as primary is the first screen returned, // not what shows up in the config tool as [1], [2], ... // -and info.screen_number just seems to be useless (0 for first returned, 1 for next, ...) di.number = info.screen_number + 1; } XFree(queried); } else { log(Warning, "Xinerama is not active"); } } else { log(Warning, "Xinerama extension is not installed"); } }
int x11_shadow_xinerama_init(x11ShadowSubsystem* subsystem) { #ifdef WITH_XINERAMA int index; int numMonitors; int major, minor; int xinerama_event; int xinerama_error; MONITOR_DEF* monitor; XineramaScreenInfo* screen; XineramaScreenInfo* screens; if (!XineramaQueryExtension(subsystem->display, &xinerama_event, &xinerama_error)) return -1; if (!XDamageQueryVersion(subsystem->display, &major, &minor)) return -1; if (!XineramaIsActive(subsystem->display)) return -1; screens = XineramaQueryScreens(subsystem->display, &numMonitors); if (numMonitors > 16) numMonitors = 16; if (!screens || (numMonitors < 1)) return -1; subsystem->monitorCount = numMonitors; for (index = 0; index < numMonitors; index++) { screen = &screens[index]; monitor = &(subsystem->monitors[index]); monitor->left = screen->x_org; monitor->top = screen->y_org; monitor->right = monitor->left + screen->width; monitor->bottom = monitor->top + screen->height; monitor->flags = (index == 0) ? 1 : 0; } XFree(screens); #endif return 1; }
//========================================= // CountScreens //----------------------------------------- void CountScreens (Display *dpy) { int s_num,count; if ( XineramaIsActive(dpy)) { screens = XineramaQueryScreens(dpy, &s_num); scr_count = s_num; for (count = 0;count < scr_count; count++) { scr[count] = screens[count].screen_number; } scr_count = 1; } else { scr_count = ScreenCount(dpy); for (count = 0;count < scr_count; count++) { scr[count] = count; } } }
/** Init screen geo */ void screen_init_geo(void) { int i; int s = screen_count(); sgeo = xcalloc(s, sizeof(XRectangle)); spgeo = xcalloc(s, sizeof(XRectangle)); for(i = 0; i < s; ++i) sgeo[i] = screen_get_geo(i); spgeo[0].x = 0; spgeo[0].y = 0; spgeo[0].width = MAXW; spgeo[0].height = MAXH; #ifdef HAVE_XINERAMA XineramaScreenInfo *xsi; int n; if(XineramaIsActive(dpy)) { xsi = XineramaQueryScreens(dpy, &n); for(i = 0; i < n; ++i) { spgeo[i].x = xsi[i].x_org; spgeo[i].y = xsi[i].y_org; spgeo[i].width = xsi[i].width; spgeo[i].height = xsi[i].height; } XFree(xsi); } #endif /* HAVE_XINERAMA */ #ifdef HAVE_XRANDR /* Init xrandr stuff */ int d; XRRSelectInput(dpy, ROOT, 1); XRRQueryExtension(dpy, &xrandr_event, &d); #endif /* HAVE_XRANDR */ ewmh_set_desktop_geometry(); return; }
static gboolean init_xfree_xinerama (GdkScreen *screen) { #ifdef HAVE_XFREE_XINERAMA Display *dpy = GDK_SCREEN_XDISPLAY (screen); GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); XineramaScreenInfo *monitors; int i, n_monitors; if (!XineramaIsActive (dpy)) return FALSE; monitors = XineramaQueryScreens (dpy, &n_monitors); if (n_monitors <= 0 || monitors == NULL) { /* If Xinerama doesn't think we have any monitors, try acting as * though we had no Xinerama. If the "no monitors" condition * is because XRandR 1.2 is currently switching between CRTCs, * we'll be notified again when we have our monitor back, * and can go back into Xinerama-ish mode at that point. */ if (monitors) XFree (monitors); return FALSE; } x11_screen->n_monitors = n_monitors; x11_screen->monitors = g_new0 (GdkX11Monitor, n_monitors); for (i = 0; i < n_monitors; ++i) { init_monitor_geometry (&x11_screen->monitors[i], monitors[i].x_org, monitors[i].y_org, monitors[i].width, monitors[i].height); } XFree (monitors); x11_screen->primary_monitor = 0; return TRUE; #endif /* HAVE_XFREE_XINERAMA */ return FALSE; }
/** Startup screens. */ void StartupScreens() { #ifdef USE_XINERAMA XineramaScreenInfo *info; int x; if(XineramaIsActive(display)) { info = XineramaQueryScreens(display, &screenCount); screens = Allocate(sizeof(ScreenType) * screenCount); for(x = 0; x < screenCount; x++) { screens[x].index = x; screens[x].x = info[x].x_org; screens[x].y = info[x].y_org; screens[x].width = info[x].width; screens[x].height = info[x].height; } JXFree(info); } else { screenCount = 1; screens = Allocate(sizeof(ScreenType)); screens->index = 0; screens->x = 0; screens->y = 0; screens->width = rootWidth; screens->height = rootHeight; } #else screenCount = 1; screens = Allocate(sizeof(ScreenType)); screens->index = 0; screens->x = 0; screens->y = 0; screens->width = rootWidth; screens->height = rootHeight; #endif /* USE_XINERAMA */ }
void wInitXinerama(WScreen * scr) { scr->xine_info.primary_head = 0; scr->xine_info.screens = NULL; scr->xine_info.count = 0; #ifdef USE_XINERAMA # ifdef SOLARIS_XINERAMA if (XineramaGetState(dpy, scr->screen)) { WXineramaInfo *info = &scr->xine_info; XRectangle head[MAXFRAMEBUFFERS]; unsigned char hints[MAXFRAMEBUFFERS]; int i; if (XineramaGetInfo(dpy, scr->screen, head, hints, &info->count)) { info->screens = wmalloc(sizeof(WMRect) * (info->count + 1)); for (i = 0; i < info->count; i++) { info->screens[i].pos.x = head[i].x; info->screens[i].pos.y = head[i].y; info->screens[i].size.width = head[i].width; info->screens[i].size.height = head[i].height; } } } # else /* !SOLARIS_XINERAMA */ if (XineramaIsActive(dpy)) { XineramaScreenInfo *xine_screens; WXineramaInfo *info = &scr->xine_info; int i; xine_screens = XineramaQueryScreens(dpy, &info->count); info->screens = wmalloc(sizeof(WMRect) * (info->count + 1)); for (i = 0; i < info->count; i++) { info->screens[i].pos.x = xine_screens[i].x_org; info->screens[i].pos.y = xine_screens[i].y_org; info->screens[i].size.width = xine_screens[i].width; info->screens[i].size.height = xine_screens[i].height; } XFree(xine_screens); } # endif /* !SOLARIS_XINERAMA */ #endif /* USE_XINERAMA */ }
static XineramaScreenInfo *FXineramaQueryScreens(Display *d, int *nscreens) { if (FScreenHaveXinerama == 0) { *nscreens = 0; return NULL; } if (FScreenHaveSolarisXinerama == 1) { return solaris_XineramaQueryScreens(d, nscreens); } else { return XineramaQueryScreens(d, nscreens); } }
/* Yes I stole this from dmenu */ void updategeom() { int a, j, di, i = 0, area = 0, x, y; unsigned int du; Window w, pw, dw, *dws; XWindowAttributes wa; int n; XineramaScreenInfo *info; if((info = XineramaQueryScreens(dpy, &n))) { XGetInputFocus(dpy, &w, &di); if(w != root && w != PointerRoot && w != None) { /* find top-level window containing current input focus */ do { if(XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws) XFree(dws); } while(w != root && w != pw); /* find xinerama screen with which the window intersects most */ if(XGetWindowAttributes(dpy, pw, &wa)) for(j = 0; j < n; j++) if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { area = a; i = j; } } /* no focused window is on screen, so use pointer location instead */ if(!area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) for(i = 0; i < n; i++) if(INTERSECT(x, y, 1, 1, info[i])) break; xoff = info[i].x_org; yoff = info[i].y_org; sw = info[i].width; sh = info[i].height; XFree(info); } else { xoff = 0; yoff = 0; sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); } }
int main(int argc, char **argv) { if (argc != 9) { fprintf(stderr, "Usage %s [WA X] [WA Y] [WA W] [WA H] [WIN X] [WIN Y] [WIN W] [WIN H]\n", argv[0]); return 1; } wa_sx = atoi(argv[1]); wa_sy = atoi(argv[2]); wa_ex = wa_sx + atoi(argv[3]); wa_ey = wa_sy + atoi(argv[4]); win_sx = atoi(argv[5]); win_sy = atoi(argv[6]); win_ex = win_sx + atoi(argv[7]); win_ey = win_sy + atoi(argv[8]); Display *dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf(stderr, "error: cannot open the display\n"); return 1; } int n; XineramaScreenInfo *info; int screen = DefaultScreen(dpy); if (info = XineramaQueryScreens(dpy, &n)) { int i; for (i = 0; i < n; ++ i) { process_screen(info[i].x_org, info[i].y_org, info[i].x_org + info[i].width, info[i].y_org + info[i].height); } } else { process_screen(0, 0, DisplayWidth(dpy, screen), DisplayHeight(dpy, screen)); } XFree(info); XCloseDisplay(dpy); printf("%d %d %d %d", _sx, _sy, _ex - _sx, _ey - _sy); return 0; }
DC * initdc(void) { DC *dc; if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("no locale support\n", stderr); if(!(dc = calloc(1, sizeof *dc))) eprintf("cannot malloc %u bytes:", sizeof *dc); if(!(dc->dpy = XOpenDisplay(NULL))) eprintf("cannot open display\n"); if(!(dc->info = XineramaQueryScreens(dc->dpy, &dc->scrcount))){ dc->scrcount = 1; } dc->menus = calloc(dc->scrcount, sizeof(DM)); dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL); XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter); return dc; }
static void queryscreeninfo(Display *dpy, XRectangle *rect, int screen) { XineramaScreenInfo *xsi = NULL; int nscreens = 1; if(XineramaIsActive(dpy)) xsi = XineramaQueryScreens(dpy, &nscreens); if(xsi == NULL || screen > nscreens || screen <= 0) { qsi_no_xinerama(dpy, rect); } else { rect->x = xsi[screen-1].x_org; rect->y = xsi[screen-1].y_org; rect->width = xsi[screen-1].width; rect->height = xsi[screen-1].height; } }
int xf_list_monitors(xfContext* xfc) { #ifdef WITH_XINERAMA Display* display; int i, nmonitors = 0; int ignored, ignored2; XineramaScreenInfo* screen = NULL; display = XOpenDisplay(NULL); if (XineramaQueryExtension(display, &ignored, &ignored2)) { if (XineramaIsActive(display)) { screen = XineramaQueryScreens(display, &nmonitors); for (i = 0; i < nmonitors; i++) { printf(" %s [%d] %dx%d\t+%d+%d\n", (i == 0) ? "*" : " ", i, screen[i].width, screen[i].height, screen[i].x_org, screen[i].y_org); } XFree(screen); } } XCloseDisplay(display); #else Screen* screen; Display* display; display = XOpenDisplay(NULL); screen = ScreenOfDisplay(display, DefaultScreen(display)); printf(" * [0] %dx%d\t+%d+%d\n", WidthOfScreen(screen), HeightOfScreen(screen), 0, 0); XCloseDisplay(display); #endif return 0; }
/** Count the screens *\return the number of screen */ int screen_count(void) { int n = 0; n = ScreenCount(dpy); #ifdef HAVE_XINERAMA if(XineramaIsActive(dpy)) XineramaQueryScreens(dpy, &n); #endif /* HAVE_XINERAMA */ /* Set _WMFS_SCREEN_COUNT */ if(net_atom) XChangeProperty(dpy, ROOT, net_atom[wmfs_screen_count], XA_CARDINAL, 32, PropModeReplace, (uchar*)&n, 1); return n; }
static void initXinerama(void) { xineInfo.screens = NULL; xineInfo.count = 0; #ifdef USE_XINERAMA # ifdef SOLARIS_XINERAMA if (XineramaGetState(dpy, scr)) { XRectangle head[MAXFRAMEBUFFERS]; unsigned char hints[MAXFRAMEBUFFERS]; int i; if (XineramaGetInfo(dpy, scr, head, hints, &xineInfo.count)) { xineInfo.screens = wmalloc(sizeof(WMRect) * (xineInfo.count + 1)); for (i = 0; i < xineInfo.count; i++) { xineInfo.screens[i].pos.x = head[i].x; xineInfo.screens[i].pos.y = head[i].y; xineInfo.screens[i].size.width = head[i].width; xineInfo.screens[i].size.height = head[i].height; } } } # else /* !SOLARIS_XINERAMA */ if (XineramaIsActive(dpy)) { XineramaScreenInfo *xine_screens; int i; xine_screens = XineramaQueryScreens(dpy, &xineInfo.count); xineInfo.screens = wmalloc(sizeof(WMRect) * (xineInfo.count + 1)); for (i = 0; i < xineInfo.count; i++) { xineInfo.screens[i].pos.x = xine_screens[i].x_org; xineInfo.screens[i].pos.y = xine_screens[i].y_org; xineInfo.screens[i].size.width = xine_screens[i].width; xineInfo.screens[i].size.height = xine_screens[i].height; } XFree(xine_screens); } # endif /* !SOLARIS_XINERAMA */ #endif /* USE_XINERAMA */ }
void screenMetrics(int *x_org, int *y_org, int *width, int *height){ // Open the X Display; passing NULL returns the default display. Display* display = XOpenDisplay(NULL); // Raw screen information from the X server. Screen* screen = XScreenOfDisplay(display, DefaultScreen(display)); // Xinerama screen information; if available, this info is more accurate. // This is especially important for multi-monitor configurations. int screen_count = 0; XineramaScreenInfo *screen_info = XineramaQueryScreens(display, &screen_count); // If screen_info is not NULL, we got preferred measurements from Xinerama, // otherwise we use the measurements from the X server. if(screen_info != NULL){ // screen_info is an array of length screen_count // Index zero should hold the "default" or "primary" // screen as configured by the user. *x_org = screen_info[0].x_org; *y_org = screen_info[0].y_org; *width = screen_info[0].width; *height = screen_info[0].height; }else{ // screen is a reference to the default X Server screen // Since we know Xinerama isn't running, this screen // should correspond to exactly one physical display. *x_org = 0; *y_org = 0; *width = screen->width; *height = screen->height; } // Release the Xinerama screen info, if we have it. if(screen_info != NULL){ XFree(screen_info); } // Release the connection to the X Display XCloseDisplay(display); return; }