pax_global_header00006660000000000000000000000064124257631040014516gustar00rootroot0000000000000052 comment=36b69ca4c8b56adc1572a82a0167931cda30754b xininfo-0.14.11/000077500000000000000000000000001242576310400133345ustar00rootroot00000000000000xininfo-0.14.11/.gitignore000066400000000000000000000000151242576310400153200ustar00rootroot00000000000000build/ *.swp xininfo-0.14.11/LICENSE000066400000000000000000000021031242576310400143350ustar00rootroot00000000000000MIT/X11 License Copyright (c) 2014 Qball Cow Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. xininfo-0.14.11/Makefile000066400000000000000000000051201242576310400147720ustar00rootroot00000000000000QUIET?=@ CFLAGS?=-Wall -Wextra -O3 -g VERSION?=0.14.11 PROGRAM=xininfo MANPAGE_SOURCE=$(PROGRAM).markdown MANPAGE=$(PROGRAM).1 PREFIX?=$(DESTDIR)/usr BIN_DIR?=$(PREFIX)/bin SOURCE_DIR=source CONFIG_DIR=config DOC_DIR=doc BUILD_DIR=build SOURCES=$(wildcard $(SOURCE_DIR)/*.c $(CONFIG_DIR)/*.c ) OBJECTS=$(SOURCES:%.c=$(BUILD_DIR)/%.o) HEADERS=$(wildcard include/*.h) OTHERS=Makefile LICENSE doc/xininfo.1 doc/xininfo.markdown INSTALL_PROGRAM=$(BIN_DIR)/$(PROGRAM) INSTALL_MANPAGE=$(PREFIX)/share/man/man1/$(MANPAGE) DIST_TARGET=$(BUILD_DIR)/$(PROGRAM)-$(VERSION).tar.xz CFLAGS+=-std=c99 CFLAGS+=-Iinclude/ CFLAGS+=-DVERSION="\"$(VERSION)\"" -DMANPAGE_PATH="\"$(INSTALL_MANPAGE)\"" LDADD=-lm # Check deps. ifeq (${DEBUG},1) CFLAGS+=-DTIMING=1 -g3 LDADD+=-lrt endif CLANG=$(shell which clang) ifneq (${CLANG},${EMPTY}) $(info Using clang compiler: ${CLANG}) CC=${CLANG} endif ## # Check dependencies ## PKG_CONFIG?=$(shell which pkg-config) ifeq (${PKG_CONFIG},${EMPTY}) $(error Failed to find pkg-config. Please install pkg-config) endif CFLAGS+=$(shell ${PKG_CONFIG} --cflags x11 xinerama xrandr ) LDADD+=$(shell ${PKG_CONFIG} --libs x11 xinerama xrandr ) ifeq (${LDADD},${EMPTY}) $(error Failed to find the required dependencies: x11, xinerama ) endif all: $(BUILD_DIR)/$(PROGRAM) $(BUILD_DIR): $(info Creating build dir) $(QUIET)mkdir -p $@ $(QUIET)mkdir -p $@/$(SOURCE_DIR) $(QUIET)mkdir -p $@/$(CONFIG_DIR) $(QUIET)mkdir -p $@/$(DOC_DIR) # Objects depend on header files and makefile too. $(BUILD_DIR)/%.o: %.c Makefile $(HEADERS) | $(BUILD_DIR) $(info Compiling $< -> $@) $(QUIET) $(CC) $(CFLAGS) -c -o $@ $< $(BUILD_DIR)/$(PROGRAM): $(OBJECTS) $(info Linking $@) $(QUIET)$(CC) -o $@ $^ $(LDADD) $(LDFLAGS) $(BUILD_DIR)/$(DOC_DIR)/$(MANPAGE): $(DOC_DIR)/$(MANPAGE_SOURCE) $(info geerate manpage $^-> $@) $(QUIET)md2man-roff $^ > $@ $(INSTALL_PROGRAM): $(BUILD_DIR)/$(PROGRAM) $(info Install $^ -> $@ ) $(QUIET)install -Dm 755 $^ $@ $(INSTALL_MANPAGE): $(BUILD_DIR)/$(DOC_DIR)/$(MANPAGE) $(info Install $^ -> $@ ) $(QUIET)install -Dm 755 $^ $@ install: $(INSTALL_PROGRAM) $(INSTALL_MANPAGE) clean: $(info Clean build dir) $(QUIET)rm -rf $(BUILD_DIR) indent: @astyle --style=linux -S -C -D -N -H -L -W3 -f $(SOURCES) $(HEADERS) dist: $(DIST_TARGET) $(BUILD_DIR)/$(PROGRAM)-$(VERSION): $(SOURCES) $(HEADERS) $(OTHERS) | $(BUILD_DIR) $(info Create release directory) $(QUIET)mkdir -p $@ $(QUIET)cp -a --parents $^ $@ $(DIST_TARGET): $(BUILD_DIR)/$(PROGRAM)-$(VERSION) $(info Creating release tarball: $@) $(QUIET) tar -C $(BUILD_DIR) -cavvJf $@ $(PROGRAM)-$(VERSION) xininfo-0.14.11/doc/000077500000000000000000000000001242576310400141015ustar00rootroot00000000000000xininfo-0.14.11/doc/xininfo.1000066400000000000000000000036751242576310400156500ustar00rootroot00000000000000.TH XININFO 1 xininfo .SH NAME .PP xininfo \- a tool to query the layout and size of each configured monitor. .SH SYNOPSIS .PP \fBxininfo\fP [\-monitor \fIid\fP] [\-active\-mon] [\-mon\-size] [ \-mon\-width ] [ \-mon\-height ] [ \-mon\-x ] [ \-mon\-y ] [ \-mon\-pos ] [ \-num\-mon ] [ \-max\-mon\-width ] [ \-max\-mon\-height ] [ \-print ] .SH DESCRIPTION .PP \fBxininfo\fP is an X11 utility to query the current layout and size of each configured monitor. It is designed to be used by scripts. .SH License .PP MIT/X11 .SH USAGE .PP \fBxininfo\fP accepts the following commands. Multiple commands can be concatenated. All information returned is in number of pixels. .PP \fB\fCmonitor\fR \fIid\fP .PP .RS .nf Set queried monitor to *id*. By default it uses the active monitor. .fi .RE .PP \fB\fCactive\-mon\fR .PP .RS .nf Query the *id* of the active monitor. **Prints**: *id* .fi .RE .PP \fB\fCmon\-size\fR .PP .RS .nf Get the size of the monitor. **Prints**: *width* *height* .fi .RE .PP \fB\fCmon\-width\fR .PP .RS .nf Get the width of the monitor: **Prints**: *width* .fi .RE .PP \fB\fCmon\-height\fR .PP .RS .nf Get the height of the monitor: **Prints**: *height* .fi .RE .PP \fB\fCmon\-x\fR .PP .RS .nf Get the x position of the monitor: **Prints**: *x* .fi .RE .PP \fB\fCmon\-y\fR .PP .RS .nf Get the y position of the monitor: **Prints**: *y* .fi .RE .PP \fB\fCmon\-pos\fR .PP .RS .nf Get the position of the monitor: **Prints**: *x* *y* .fi .RE .PP \fB\fCnum\-mon\fR .PP .RS .nf Queries the number of configured monitors. **Prints**: *#monitors* .fi .RE .PP \fB\fCmax\-mon\-width\fR .PP .RS .nf Query width of the monitor with the most horizontal pixels **Prints**: *width* .fi .RE .PP \fB\fCmax\-mon\-height\fR .PP .RS .nf Query height of the monitor with the most vertical pixels **Prints**: *width* .fi .RE .PP \fB\fCprint\fR .PP .RS .nf Print out all information in a human readable format. .fi .RE .SH AUTHOR .PP Qball Cow \[la]qball@gmpclient.org\[ra] xininfo-0.14.11/doc/xininfo.markdown000066400000000000000000000033741242576310400173260ustar00rootroot00000000000000# XININFO 1 xininfo ## NAME xininfo - a tool to query the layout and size of each configured monitor. ## SYNOPSIS **xininfo** [-monitor *id*] [-active-mon] [-mon-size] [ -mon-width ] [ -mon-height ] [ -mon-x ] [ -mon-y ] [ -mon-pos ] [ -num-mon ] [ -max-mon-width ] [ -max-mon-height ] [ -print ] [-help] [ -name ] ## DESCRIPTION **xininfo** is an X11 utility to query the current layout and size of each configured monitor. It is designed to be used by scripts. ## License MIT/X11 ## USAGE **xininfo** accepts the following commands. Multiple commands can be concatenated. All information returned is in number of pixels. `monitor` *id* Set queried monitor to *id*. By default it uses the active monitor. `active-mon` Query the *id* of the active monitor. **Prints**: *id* `mon-size` Get the size of the monitor. **Prints**: *width* *height* `mon-width` Get the width of the monitor: **Prints**: *width* `mon-height` Get the height of the monitor: **Prints**: *height* `mon-x` Get the x position of the monitor: **Prints**: *x* `mon-y` Get the y position of the monitor: **Prints**: *y* `mon-pos` Get the position of the monitor: **Prints**: *x* *y* `num-mon` Queries the number of configured monitors. **Prints**: *#monitors* `max-mon-width` Query width of the monitor with the most horizontal pixels **Prints**: *width* `max-mon-height` Query height of the monitor with the most vertical pixels **Prints**: *width* `print` Print out all information in a human readable format. `-name` Print the xrandr name of the monitor. `-h` `-help` Show the manpage of **xininfo** ## AUTHOR Qball Cow xininfo-0.14.11/source/000077500000000000000000000000001242576310400146345ustar00rootroot00000000000000xininfo-0.14.11/source/xininfo.c000066400000000000000000000332221242576310400164540ustar00rootroot00000000000000/** * xininfo * * MIT/X11 License * Copyright (c) 2014 Qball Cow * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define NEAR(a,o,b) ((b) > (a)-(o) && (b) < (a)+(o)) #define OVERLAP(a,b,c,d) (((a)==(c) && (b)==(d)) || MIN((a)+(b), (c)+(d)) - MAX((a), (c)) > 0) #define INTERSECT(x,y,w,h,x1,y1,w1,h1) (OVERLAP((x),(w),(x1),(w1)) && OVERLAP((y),(h),(y1),(h1))) // CLI: argument parsing static int find_arg( const int argc, char * const argv[], const char * const key ) { int i; for ( i = 0; i < argc && strcasecmp( argv[i], key ); i++ ); return i < argc ? i: -1; } static void find_arg_int ( int argc, char *argv[], char *key, int * val ) { int i = find_arg( argc, argv, key ); if ( val != NULL && i > 0 && i < argc-1 ) { *val = strtol( argv[i+1], NULL, 10 ); } } // Monitor layout stuff. typedef struct { int x,y; int w,h; char *name; } MMB_Rectangle; typedef struct { // Size of the total screen area. MMB_Rectangle base; // Number of monitors. int num_monitors; // List of monitors; MMB_Rectangle *monitors; // Mouse position MMB_Rectangle active_monitor; } MMB_Screen; // find active_monitor pointer location static int pointer_get( Display *display, Window root, int *x, int *y ) { *x = 0; *y = 0; Window rr, cr; int rxr, ryr, wxr, wyr; unsigned int mr; if ( XQueryPointer( display, root, &rr, &cr, &rxr, &ryr, &wxr, &wyr, &mr ) ) { *x = rxr; *y = ryr; return 1; } return 0; } // retrieve a property of any type from a window static int window_get_prop( Display *display, Window w, Atom prop, Atom *type, int *items, void *buffer, unsigned int bytes ) { Atom _type; if ( !type ) type = &_type; int _items; if ( !items ) items = &_items; int format; unsigned long nitems, nbytes; unsigned char *ret = NULL; memset( buffer, 0, bytes ); if ( XGetWindowProperty( display, w, prop, 0, bytes/4, False, AnyPropertyType, type, &format, &nitems, &nbytes, &ret ) == Success && ret && *type != None && format ) { if ( format == 8 ) memmove( buffer, ret, MIN( bytes, nitems ) ); if ( format == 16 ) memmove( buffer, ret, MIN( bytes, nitems * sizeof( short ) ) ); if ( format == 32 ) memmove( buffer, ret, MIN( bytes, nitems * sizeof( long ) ) ); *items = ( int )nitems; XFree( ret ); return 1; } return 0; } static XWindowAttributes* window_get_attributes( Display *display,Window w ) { XWindowAttributes *cattr = malloc( sizeof( XWindowAttributes ) ); if ( XGetWindowAttributes( display, w, cattr ) ) { return cattr; } return NULL; } // determine which monitor holds the active window, or failing that the active_monitor pointer static void monitor_active( Display *display, MMB_Screen *mmb_screen ) { Screen* screen = DefaultScreenOfDisplay( display ); Window root = RootWindow( display, XScreenNumberOfScreen( screen ) ); Window id; Atom type; int count; Atom reqatom = XInternAtom ( display,"_NET_ACTIVE_WINDOW" , False ); if ( window_get_prop( display, root, reqatom, &type, &count, &id, sizeof( Window ) ) && type == XA_WINDOW && count > 0 ) { XWindowAttributes *attr = window_get_attributes( display, id ); if(attr != NULL ) { Window junkwin; int x,y; if ( XTranslateCoordinates ( display, id, attr->root, -attr->border_width, -attr->border_width, &x, &y, &junkwin ) == True ) { mmb_screen->active_monitor.x = x; mmb_screen->active_monitor.y = y; } free( attr ); return; } } int x, y; if ( pointer_get( display, root, &x, &y ) ) { mmb_screen->active_monitor.x = x; mmb_screen->active_monitor.y = y; return; } } /** * @param display An X11 Display * * Create MMB_Screen that holds the monitor layout of display. * * @returns filled in MMB_Screen */ static MMB_Screen *mmb_screen_create( Display *display ) { // Create empty structure. MMB_Screen *retv = malloc( sizeof( *retv ) ); memset( retv, 0, sizeof( *retv ) ); Screen *screen = DefaultScreenOfDisplay( display ); retv->base.w = WidthOfScreen( screen ); retv->base.h = HeightOfScreen( screen ); // Parse xinerama setup. if ( XineramaIsActive( display ) ) { XineramaScreenInfo *info = XineramaQueryScreens( display, &( retv->num_monitors ) ); if ( info != NULL ) { retv->monitors = malloc( retv->num_monitors*sizeof( MMB_Rectangle ) ); for ( int i = 0; i < retv->num_monitors; i++ ) { retv->monitors[i].x = info[i].x_org; retv->monitors[i].y = info[i].y_org; retv->monitors[i].w = info[i].width; retv->monitors[i].h = info[i].height; retv->monitors[i].name = NULL; } XFree( info ); } } if ( retv->monitors == NULL ) { retv->num_monitors = 1; retv->monitors = malloc( 1*sizeof( MMB_Rectangle ) ); retv->monitors[0] = retv->base; } monitor_active( display, retv ); return retv; } /** * @param screen a Pointer to the MMB_Screen pointer to free. * * Free MMB_Screen object and set pointer to NULL. */ static void mmb_screen_free( MMB_Screen **screen ) { if ( screen == NULL || *screen == NULL ) return; if ( ( *screen )->active_monitor.name ) { free( ( *screen )->active_monitor.name ); } for ( int i = 0; i < ( *screen )->num_monitors; i++ ) { if ( ( *screen )->monitors[i].name ) { free( ( *screen )->monitors[i].name ); } } if ( ( *screen )->monitors != NULL ) { free( ( *screen )->monitors ); } free( *screen ); screen = NULL; } static int mmb_screen_get_active_monitor( const MMB_Screen *screen ) { for ( int i =0; i < screen->num_monitors; i++ ) { if ( INTERSECT( screen->active_monitor.x, screen->active_monitor.y, 1,1, screen->monitors[i].x, screen->monitors[i].y, screen->monitors[i].w, screen->monitors[i].h ) ) { return i; } } return 0; } static void mmb_screen_print( const MMB_Screen *screen ) { printf( "Total size: %d %d\n", screen->base.w, screen->base.h ); printf( "Num. monitors: %d\n", screen->num_monitors ); for ( int i =0; i < screen->num_monitors; i++ ) { printf( " %01d: %d %d -> %d %d\n", i, screen->monitors[i].x, screen->monitors[i].y, screen->monitors[i].w, screen->monitors[i].h ); } int active_monitor = mmb_screen_get_active_monitor( screen ); printf( "Active mon: %d\n", active_monitor ); printf( " %d-%d\n", screen->active_monitor.x, screen->active_monitor.y ); } // X error handler static int ( *xerror )( Display *, XErrorEvent * ); int X11_oops( Display *display, XErrorEvent *ee ) { if ( ee->error_code == BadWindow || ( ee->request_code == X_GrabButton && ee->error_code == BadAccess ) || ( ee->request_code == X_GrabKey && ee->error_code == BadAccess ) ) return 0; fprintf( stderr, "error: request code=%d, error code=%d\n", ee->request_code, ee->error_code ); return xerror( display, ee ); } static void help () { int code = execlp ( "man", "man", MANPAGE_PATH, NULL ); if ( code == -1 ) { fprintf ( stderr, "Failed to execute man: %s\n", strerror ( errno ) ); } } static void info( const MMB_Screen *screen, Display *display ) { Window root = RootWindow( display, 0 ); XRRScreenResources *rs = XRRGetScreenResources ( display, root ); if ( rs != NULL ) { for ( int i = 0; i < rs->noutput; i++ ) { XRROutputInfo *info = XRRGetOutputInfo ( display, rs, rs->outputs[i] ); if ( info ) { if ( info->connection == RR_Connected ) { XRRCrtcInfo *ci = XRRGetCrtcInfo( display, rs, info->crtc ); for ( int m =0; m < screen->num_monitors; m++ ) { if ( INTERSECT( ci->x, ci->y, 1,1, screen->monitors[m].x, screen->monitors[m].y, screen->monitors[m].w, screen->monitors[m].h ) ) { screen->monitors[m].name = strdup( info->name ); } } XRRFreeCrtcInfo( ci ); } XRRFreeOutputInfo( info ); } } XRRFreeScreenResources( rs ); } } int main ( int argc, char **argv ) { Display *display; if ( find_arg( argc, argv, "-h" ) >= 0 || find_arg( argc, argv, "-help" ) >= 0 ) { help(); return 0; } // Get DISPLAY const char *display_str= getenv( "DISPLAY" ); if ( !( display = XOpenDisplay( display_str ) ) ) { fprintf( stderr, "cannot open display!\n" ); return EXIT_FAILURE; } // Setup error handler. XSync( display, False ); xerror = XSetErrorHandler( X11_oops ); XSync( display, False ); // Get monitor layout. (xinerama aware) MMB_Screen *mmb_screen = mmb_screen_create( display ); info( mmb_screen, display ); int monitor_pos = mmb_screen_get_active_monitor( mmb_screen ); find_arg_int( argc, argv, "-monitor", &monitor_pos ); if ( !( monitor_pos >= 0 && monitor_pos < mmb_screen->num_monitors ) ) { fprintf( stderr, "Invalid monitor: %d (0 <= %d < %d failed)\n", monitor_pos, monitor_pos, mmb_screen->num_monitors ); // Cleanup mmb_screen_free( &mmb_screen ); XCloseDisplay( display ); return EXIT_FAILURE; } if ( find_arg( argc, argv, "-active-mon" ) >= 0 ) { unsigned int mon = mmb_screen_get_active_monitor( mmb_screen ); printf( "%d\n", mon ); } if ( find_arg( argc, argv, "-mon-size" ) >= 0 ) { printf( "%i %i\n", mmb_screen->monitors[monitor_pos].w,mmb_screen->monitors[monitor_pos].h ); } if ( find_arg( argc, argv, "-mon-width" ) >= 0 ) { printf( "%i\n", mmb_screen->monitors[monitor_pos].w ); } if ( find_arg( argc, argv, "-mon-height" ) >= 0 ) { printf( "%i\n", mmb_screen->monitors[monitor_pos].h ); } if ( find_arg( argc, argv, "-mon-x" ) >= 0 ) { printf( "%i\n", mmb_screen->monitors[monitor_pos].x ); } if ( find_arg( argc, argv, "-mon-y" ) >= 0 ) { printf( "%i\n", mmb_screen->monitors[monitor_pos].y ); } if ( find_arg( argc, argv, "-mon-pos" ) >= 0 ) { printf( "%i %i\n", mmb_screen->monitors[monitor_pos].x,mmb_screen->monitors[monitor_pos].y ); } if ( find_arg( argc, argv, "-num-mon" ) >= 0 ) { printf( "%u\n", mmb_screen->num_monitors ); } if( find_arg( argc, argv, "-name" ) >= 0 ) { if(mmb_screen->monitors[monitor_pos].name){ printf( "%s\n", mmb_screen->monitors[monitor_pos].name); }else{ printf("unknown\n"); } } if ( find_arg( argc, argv, "--max-mon-width" ) >= 0 || find_arg( argc, argv, "-max-mon-width" ) >= 0 ) { int maxw = 0; for ( int i = 0; i < mmb_screen->num_monitors; i++ ) { maxw = MAX( maxw, mmb_screen->monitors[i].w ); } printf( "%i\n", maxw ); } if ( find_arg( argc, argv, "--max-mon-height" ) >= 0 || find_arg( argc, argv, "-max-mon-height" ) >= 0 ) { int maxh = 0; for ( int i = 0; i < mmb_screen->num_monitors; i++ ) { maxh = MAX( maxh, mmb_screen->monitors[i].h ); } printf( "%i\n", maxh ); } // Print layout if ( find_arg( argc, argv, "-print" ) >= 0 ) { mmb_screen_print( mmb_screen ); } // Cleanup mmb_screen_free( &mmb_screen ); XCloseDisplay( display ); }