Esempio n. 1
0
static Window
findWindowByTitle(Display *dpy, int scr, Window start, const char *pattern)
{
	unsigned int i, num;
	Window root, parent, *children;
	char *title;

	/*
	XSynchronize(dpy, 1);
	crDebug("%s %d 0x%x %s", __FUNCTION__, scr, (int) start, pattern);
	*/

	if (XFetchName(dpy, start, &title)) {
		char *match = crStrPatternMatch(title, pattern);
		XFree(title);
		if (match)
			return start; /* found it */
	}
 
	/* breadth-first search */
	if (XQueryTree(dpy, start, &root, &parent, &children, &num)) {
		/* test each child window for a match */
		for (i = 0; i < num; i++) {
			/*
			crDebug("%s i=%d/%d win=0x%x", __FUNCTION__, i, num, (int) children[i]);
			*/
			Window w = children[i];
			if (XFetchName(dpy, w, &title)) {
				char *match = crStrPatternMatch(title, pattern);
				XFree(title);
				if (match) {
					XFree(children);
					return w; /* found it */
				}
			}
		}

		/* search the descendents of each child for a match: */
		for (i = 0; i < num ;i++) {
			Window w = findWindowByTitle(dpy, scr, children[i], pattern);
			if (w) {
				XFree(children);
				return w;
			}
		}

		XFree(children);
	}

	/* not found */
	return 0;
}
Esempio n. 2
0
File: spot.c Progetto: jdarnold/xoat
void spot_update_bar(int spot, int mon)
{
	int i, n = 0, len = 0; client *o, *c = NULL;
	char title[SPOT_BUFF]; *title = 0;
	monitor *m = &monitors[mon];

	if (spot == SPOT1)
	{
		// Show X root window name in spot1 bar
		// Use xsetroot -name for a custom status
		char *tmp = NULL;
		if (XFetchName(display, root, &tmp))
			len += snprintf(title+len, MAX(0, SPOT_BUFF-len), " %s  ", tmp);
		if (tmp) XFree(tmp);
	}
	for_windows(i, o) if (o->manage && o->spot == spot && o->monitor == mon)
	{
		if (!c) c = o;
		char *name = NULL, *tmp = NULL;
		if (!(name = window_get_text_prop(o->window, atoms[_NET_WM_NAME])))
			if (XFetchName(display, o->window, &tmp))
				name = strdup(tmp);
		if (name)
		{
			if (TITLE_ELLIPSIS > 0 && strlen(name) > TITLE_ELLIPSIS)
			{
				name = realloc(name, strlen(name)+4);
				strcpy(name+TITLE_ELLIPSIS, "...");
			}
			len += snprintf(title+len, MAX(0, SPOT_BUFF-len), " [%d] %s  ", n++, name);
			free(name);
		}
		if (tmp) XFree(tmp);
	}
	if (TITLE)
	{
		if (c && !c->full && *title && m->bars[spot])
		{
			int focus = c->window == current || (spot == current_spot && mon == current_mon);
			char *color  = focus && c->window == current ? TITLE_FOCUS : TITLE_BLUR;
			char *border = focus && c->window == current ? BORDER_FOCUS: BORDER_BLUR;
			textbox_font(m->bars[spot], TITLE, color, border);
			textbox_text(m->bars[spot], title);
			textbox_draw(m->bars[spot]);
			textbox_show(m->bars[spot]);
		}
		else
		if (m->bars[spot])
			textbox_hide(m->bars[spot]);
	}
}
Esempio n. 3
0
BZclient::BZclient( Display* dpy, Window w ) {

    XWindowAttributes attr;
    long dummy ;
    XWMHints *hints ;

    XGrabServer(dpy);
    XGetTransientForHint(dpy, w, &transient);
    XFetchName(dpy, w, &name);
    XGetWindowAttributes(dpy, w, &attr);

    window = w ;
    ignore_unmap = 0 ;
    x = attr.x ;
    y = attr.y ;
    width = attr.width ;
    height = attr.height ;
    cmap = attr.colormap ;
    size = XAllocSizeHints() ;
    
    XGetWMNormalHints(dpy, window, size, &dummy);







    XSync(dpy, False);
    XUngrabServer(dpy);


}
Esempio n. 4
0
void UpdateName(UltimateContext *uc)
{
  char *name;
  if(!XFetchName(disp, uc->win, &name)) name = NULL;
  if(uc->title.name) XFree(uc->title.name);
  uc->title.name = name;
  if(uc->title.win != None){
    if(uc->title.name) {
      int x, y, width, height;
      x = uc->title.x;
      y = uc->title.y;
      width = uc->title.width;
      height = uc->title.height;
      XResizeWindow(disp, uc->title.win,
		    uc->title.width = (XTextWidth(TheScreen.TitleFont,
                    uc->title.name, strlen(uc->title.name))
		    + (((InitS.BorderTitleFlags & BT_CENTER_TITLE) 
		        || (uc->flags & SHAPED)) ? 9 : 6)),
                    uc->title.height = (TheScreen.TitleFont->ascent
                    + TheScreen.TitleFont->descent 
		    + ((uc->flags & SHAPED) ? 6 : 3)));
      if((InitS.BorderTitleFlags & BT_CENTER_TITLE) || (uc->flags & SHAPED))
        XMoveWindow(disp, uc->title.win,
	            uc->title.x = ((uc->Attr.width - uc->title.width) / 2),
                    uc->title.y = ((uc->flags & SHAPED) ? 0
		    : (uc->BorderWidth - TheScreen.FrameBevelWidth - 1) / 2
                    + TheScreen.FrameBevelWidth));
      if((!((uc->title.width == width) && (uc->title.height == height)
          && (uc->title.x == x) && (uc->title.y == y))) && (uc->flags & SHAPED))
	 ShapeFrame(uc);
      DrawTitle(uc);
    } else XResizeWindow(disp,uc->title.win,0,0);
  }
  DBG(fprintf(TheScreen.errout,"Window Name: %s\n",uc->title.name);)
}
Esempio n. 5
0
/*
 * Window_With_Name: routine to locate a window with a given name on a display.
 *                   If no window with the given name is found, 0 is returned.
 *                   If more than one window has the given name, the first
 *                   one found will be returned.  Only top and its subwindows
 *                   are looked at.  Normally, top should be the RootWindow.
 */
Window Window_With_Name(
    Display *disp,
    Window top,
    const char *name)
{
	Window *children, dummy;
	unsigned int nchildren;
	unsigned int i;
	Window w=0;
	char *window_name;

	if (XFetchName(disp, top, &window_name) && !strcmp(window_name, name))
	  return(top);

	if (!XQueryTree(disp, top, &dummy, &dummy, &children, &nchildren))
	  return(0);

	for (i=0; i<nchildren; i++) {
		w = Window_With_Name(disp, children[i], name);
		if (w)
		  break;
	}
	if (children) XFree ((char *)children);
	return(w);
}
Esempio n. 6
0
/*
 * choose a desktop name
 */
char *choose_title(char *display) {
	static char title[(MAXN+10)];	

	memset(title, 0, MAXN+10);
	strcpy(title, "x11vnc");

	if (display == NULL) {
		display = getenv("DISPLAY");
	}
	if (display == NULL) {
		return title;
	}
	title[0] = '\0';
	if (display[0] == ':') {
		char *th = this_host();
		if (th != NULL) {
			strncpy(title, th, MAXN - strlen(title));
		}
	}
	strncat(title, display, MAXN - strlen(title));
	if (subwin && dpy && valid_window(subwin, NULL, 0)) {
		char *name = NULL;
		if (XFetchName(dpy, subwin, &name)) {
			if (name) {
				strncat(title, " ",  MAXN - strlen(title));
				strncat(title, name, MAXN - strlen(title));
				free(name);
			}
		}
	}
	return title;
}
Esempio n. 7
0
 void print_window_attrs(Display *display, Window focus_win, int &wx, int &wy){
        XWindowAttributes wattrs;
        XGetWindowAttributes(display, focus_win, &wattrs);
        char *wname;
        XFetchName(display, focus_win, &wname);
        int root_x,root_y;
        Window unused_child;
        Window root = XDefaultRootWindow(display);
        XTranslateCoordinates(display, focus_win, wattrs.root, wattrs.x, wattrs.y, &root_x, &root_y, &unused_child);


        Window root_return;
        int x_return, y_return;
        unsigned int width_return, height_return;
        unsigned int border_width_return;
        unsigned int depth_return;

        XGetGeometry(display, focus_win, &root_return, &x_return, &y_return, &width_return, 
                      &height_return, &border_width_return, &depth_return);

        debug()<<"Window Info: "<<"("<< wattrs.x <<','<< wattrs.y <<") "<< wattrs.width <<'x'<< wattrs.height<<' '<< focus_win<<' '<<wattrs.root<<std::endl
               <<"             "<<"("<< root_x   <<','<<root_y<<')'<<std::endl
               <<"             "<<"("<< x_return <<','<<y_return<<") "<<width_return<<'x'<<height_return<<' '<<root_return<<(root_return==root?'=':'x')<<std::endl
               <<' '<< wname<< std::endl;

        wx = root_x; wy = root_y; // delta (+7,+24)
}
Esempio n. 8
0
bool process_event(Display *display, XEvent ev){
    char *wm_name;
    Window focus;
    int revert;
    
    if(debug) printf("Button Press - %d\n", ev.xbutton.button);
    if(debug) printf("Pos=[%d,%d]\n", ev.xbutton.x, ev.xbutton.y);
    
    XGetInputFocus(display, &focus, &revert);
    XFetchName(display, focus, &wm_name);
    printf("wm_name == [%s]\n", wm_name);
    if(NULL != wm_name && NULL != strstr(wm_name, "com.lab126.booklet.reader_M")){
        XFree(wm_name);
    // focus in reader
        if(ev.xbutton.y > 500 && ev.xbutton.y < 1400){
            ignore_button(display, ev);
            printf("y == %d, ignore\n", ev.xbutton.y);
            return true;
        }
    }
    else{
        XFree(wm_name);
    }
    
    return false;
}
Esempio n. 9
0
void show_window(GtkButton *button, gpointer data)
{
        int i;
        char *name;
        unsigned long len;
        Window *windows;
        Atom atom;
        XWindowAttributes attr;
        XEvent xev;

        XFetchName(disp, (Window) data, &name);
        windows =  (Window*) get_windows(&len);

        g_print ("Raising: [%s]\n", name);

        for (i = 0; i < (int) len; i++) {
                if ((Window) data != windows[i]) {
                        XLowerWindow(disp, windows[i]);
                }
        }

        XRaiseWindow(disp, (Window) data);
        XFlush(disp);
        XSync(disp, False);
}
Esempio n. 10
0
static char *
GetWindowTitleHelper( Display *dpy, Window window, GLboolean recurseUp )
{
	while (1) {
		char *name;
		if (!XFetchName(dpy, window, &name))
			return NULL;
		if (name[0]) {
			return name;
		}
		else if (recurseUp) {
			/* This window has no name, try the parent */
			Status stat;
			Window root, parent, *children;
			unsigned int numChildren;
			stat = XQueryTree( dpy, window, &root, &parent,
												 &children, &numChildren );
			if (!stat || window == root)
				return NULL;
			if (children)
				XFree(children);
			window = parent;
		}
		else {
			XFree(name);
			return NULL;
		}
	}
}
Esempio n. 11
0
void map_notify_handler(XEvent local_event, Display* display, ScreenInfos infos){
	printf("----------Map Notify\n");
	XWindowAttributes win_attr;
	char *child_name;
	XGetWindowAttributes(display, local_event.xmap.window, &win_attr);
	XFetchName(display, local_event.xmap.window, &child_name);
	printf("\tAttributes: W: %d - H: %d - Name: %s - ID %lu\n", win_attr.width, win_attr.height, child_name, local_event.xmap.window);
	Window trans = None;	
	XGetTransientForHint(display, local_event.xmap.window, &trans);	
	printf("\tIs transient: %ld\n", trans);
	if(child_name!=NULL){
	  if(strcmp(child_name, "Parent") && local_event.xmap.override_redirect == False){
		Window new_win = draw_window_with_name(display, RootWindow(display, infos.screen_num), "Parent", infos.screen_num, 
						   win_attr.x, win_attr.y, win_attr.width, win_attr.height+DECORATION_HEIGHT, 0, 
						   BlackPixel(display, infos.screen_num));
		XMapWindow(display, new_win);
		XReparentWindow(display,local_event.xmap.window, new_win,0, DECORATION_HEIGHT);
		set_window_item(local_event.xmap.window, new_win);
		XSelectInput(display, local_event.xmap.window, StructureNotifyMask);
		printf("\tParent window id: %lu\n", new_win);
		put_text(display, new_win, child_name, "9x15", 10, 10, BlackPixel(display,infos.screen_num), WhitePixel(display, infos.screen_num));
	  } /*else {
		  XWindowAttributes attributes;
		  Status status = XGetWindowAttributes(display, local_event.xmap.window, &attributes);
		  printf("\tStatus: %d\n", attributes.map_state);
		  printf("\tOverride redirect: %d\n", attributes.override_redirect);
		  //XMapWindow(display, trans);
		  XFetchName(display, trans, &child_name);
		  printf("\tChild name: %s\n", child_name);
		  //XRaiseWindow(local_event.xmap.display, local_event.xmap.window);
		  //XCirculateSubwindows(local_event.xmap.display, local_event.xmap.window, RaiseLowest);
	  }*/
	}
	XFree(child_name);
}
Esempio n. 12
0
Window
xfindwind(
	Display	*dpy,
	Window	win,
	char	*name,
	int	depth
)
{
	char	*nr;
	Window	rr, pr, *cl;
	Window	wr;
	unsigned int	nc;
	register int	i;

	if (depth == 0)		/* negative depths search all */
		return(None);
	if (!XQueryTree(dpy, win, &rr, &pr, &cl, &nc) || nc == 0)
		return(None);
	wr = None;		/* breadth first search */
	for (i = 0; wr == None && i < nc; i++)
		if (XFetchName(dpy, cl[i], &nr)) {
			if (!strcmp(nr, name))
				wr = cl[i];
			free(nr);
		}
	for (i = 0; wr == None && i < nc; i++)
		wr = xfindwind(dpy, cl[i], name, depth-1);
	XFree((char *)cl);
	return(wr);
}
Esempio n. 13
0
void setOpacityRecursive ( Window w, unsigned int opacity )
{
	char* name;
	Window* children;
	Window dummy;
	unsigned int n;
	unsigned int i;

	XFetchName ( dp, w, &name );
	setOpacity ( w, opacity );

	XQueryTree ( dp, w, &dummy, &dummy, &children, &n );

	if ( n == 0 || children == NULL )
		return;

	for ( i = 0; i < n; ++i )
	{
		setOpacityRecursive ( children[i], opacity );
	}

	XFree ( children );

	return;
}
Esempio n. 14
0
/*
 * Copyright (c) 2013 Chun-Ying Huang
 *
 * This file is part of Gaming Anywere (GA).
 *
 * GA is free software; you can redistribute it and/or modify it
 * under the terms of the 3-clause BSD License as published by the
 * Free Software Foundation: http://directory.fsf.org/wiki/License:BSD_3Clause
 *
 * GA is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the 3-clause BSD License along with GA;
 * if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#ifndef WIN32
#ifndef ANDROID
#include <execinfo.h>
#endif
#include <unistd.h>
#include <sys/time.h>
#include <sys/syscall.h>
#endif
#ifdef ANDROID
#include <android/log.h>
#endif

#if !defined(WIN32) && !defined(__APPLE__) && !defined(ANDROID)
#include <X11/Xlib.h>
#endif

#include "ga-common.h"
#include "ga-conf.h"
#include "ga-avcodec.h"
#include "rtspconf.h"

#ifndef NIPQUAD
#define NIPQUAD(x)	((unsigned char*)&(x))[0],	\
			((unsigned char*)&(x))[1],	\
			((unsigned char*)&(x))[2],	\
			((unsigned char*)&(x))[3]
#endif

static char *ga_logfile = NULL;

long long
tvdiff_us(struct timeval *tv1, struct timeval *tv2) {
	struct timeval delta;
	delta.tv_sec = tv1->tv_sec - tv2->tv_sec;
	delta.tv_usec = tv1->tv_usec - tv2->tv_usec;
	if(delta.tv_usec < 0) {
		delta.tv_sec--;
		delta.tv_usec += 1000000;
	}
	return 1000000LL*delta.tv_sec + delta.tv_usec;
}

long long
ga_usleep(long long interval, struct timeval *ptv) {
	long long delta;
	struct timeval tv;
	if(ptv != NULL) {
		gettimeofday(&tv, NULL);
		delta = tvdiff_us(&tv, ptv);
		if(delta >= interval) {
			usleep(1);
			return -1;
		}
		interval -= delta;
	}
	usleep(interval);
	return 0LL;
}

static void
ga_writelog(struct timeval tv, const char *s) {
	FILE *fp;
	if(ga_logfile == NULL)
		return;
	if((fp = fopen(ga_logfile, "at")) != NULL) {
		fprintf(fp, "[%d] %ld.%06ld %s", getpid(), tv.tv_sec, tv.tv_usec, s);
		fclose(fp);
	}
	return;
}

int
ga_log(const char *fmt, ...) {
	char msg[4096];
	struct timeval tv;
	va_list ap;
	//
	gettimeofday(&tv, NULL);
	va_start(ap, fmt);
	vsnprintf(msg, sizeof(msg), fmt, ap);
	va_end(ap);
	//
	ga_writelog(tv, msg);
	//
	return 0;
}

int
ga_error(const char *fmt, ...) {
	char msg[4096];
	struct timeval tv;
	va_list ap;
	gettimeofday(&tv, NULL);
	va_start(ap, fmt);
#ifdef ANDROID
	__android_log_vprint(ANDROID_LOG_INFO, "ga_log", fmt, ap);
#else
	vsnprintf(msg, sizeof(msg), fmt, ap);
#endif
	va_end(ap);
	fprintf(stderr, "# [%d] %ld.%06ld %s", getpid(), tv.tv_sec, tv.tv_usec, msg);
	//
	ga_writelog(tv, msg);
	//
	return -1;
}

int
ga_malloc(int size, void **ptr, int *alignment) {
	if((*ptr = malloc(size+16)) == NULL)
		return -1;
#ifdef __x86_64__
	*alignment = 16 - (((long long) *ptr)&0x0f);
#else
	*alignment = 16 - (((unsigned) *ptr)&0x0f);
#endif
	return 0;
}

long
ga_gettid() {
#ifdef WIN32
	return GetCurrentThreadId();
#elif defined __APPLE__
	return pthread_mach_thread_np(pthread_self());
#elif defined ANDROID
	return gettid();
#else
	return (pid_t) syscall(SYS_gettid);
#endif
}

//调用Windows Sockets函数前的初始化
static int
winsock_init() {
#ifdef WIN32
	WSADATA wd;
	if(WSAStartup(MAKEWORD(2,2), &wd) != 0)//本函数必须是应用程序或DLL调用的第一个Windows Sockets函数.
		//它允许应用程序或DLL指明Windows Sockets API的版本号及获得特定Windows Sockets实现的细节
		return -1;
#endif
	return 0;
}


//进行初始化工作:
//1、windows sockets调用前的初始化
//2、注册av,avcodec,avformat库
//3、服务器端加载config文件,或者客户端验证url
int
ga_init(const char *config, const char *url) {
	srand(time(0));
	winsock_init();

	//某个库里面的初始化函数,看不到代码
	av_register_all();
	avcodec_register_all();
	avformat_network_init();
	
	if(config != NULL) {
		if(ga_conf_load(config) < 0) {
			ga_error("GA: cannot load configuration file '%s'\n", config);
			return -1;
		}
	}
	if(url != NULL) {
		if(ga_url_parse(url) < 0) {
			ga_error("GA: invalid URL '%s'\n", url);
			return -1;
		}
	}
	return 0;
}

void
ga_deinit() {
	return;
}

//从config结构里找出key="logfile"对应的value,并打开
void
ga_openlog() {
	char fn[1024];
	FILE *fp;
	//
	if(ga_conf_readv("logfile", fn, sizeof(fn)) == NULL)
		return;
	if((fp = fopen(fn, "at")) != NULL) {
		fclose(fp);
		ga_logfile = strdup(fn);
	}
	//
	return;
}

void
ga_closelog() {
	if(ga_logfile != NULL) {
		free(ga_logfile);
		ga_logfile = NULL;
	}
	return;
}

long
ga_atoi(const char *str) {
	// XXX: not sure why sometimes windows strtol failed on
	// handling read-only constant strings ...
	char buf[64];
	long val;
	strncpy(buf, str, sizeof(buf));
	val = strtol(buf, NULL, 0);
	return val;
}

struct gaRect *
ga_fillrect(struct gaRect *rect, int left, int top, int right, int bottom) {
	if(rect == NULL)
		return NULL;
#define SWAP(a,b)	do { int tmp = a; a = b; b = tmp; } while(0);
	if(left > right)
		SWAP(left, right);
	if(top > bottom)
		SWAP(top, bottom);
#undef	SWAP
	rect->left = left;
	rect->top = top;
	rect->right = right;
	rect->bottom = bottom;
	//
	rect->width = rect->right - rect->left + 1;
	rect->height = rect->bottom - rect->top + 1;
	rect->linesize = rect->width * RGBA_SIZE;
	rect->size = rect->width * rect->height * RGBA_SIZE;
	//
	if(rect->width <= 0 || rect->height <= 0) {
		ga_error("# invalid rect size (%dx%d)\n", rect->width, rect->height);
		return NULL;
	}
	//
	return rect;
}

//找到config中配置的window在屏幕中的位置
#ifdef WIN32
int
ga_crop_window(struct gaRect *rect, struct gaRect **prect) {
	char wndname[1024], wndclass[1024];
	char *pname;
	char *pclass;
	int dw, dh, find_wnd_arg = 0;
	HWND hWnd;
	RECT client;
	POINT lt, rb;
	//
	if(rect == NULL || prect == NULL)
		return -1;
	//
	pname = ga_conf_readv("find-window-name", wndname, sizeof(wndname));
	pclass = ga_conf_readv("find-window-class", wndclass, sizeof(wndclass));
	//
	if(pname != NULL && *pname != '\0')
		find_wnd_arg++;
	if(pclass != NULL && *pclass != '\0')
		find_wnd_arg++;
	if(find_wnd_arg <= 0) {
		*prect = NULL;
		return 0;
	}
	//
	if((hWnd = FindWindow(pclass, pname)) == NULL) {
		ga_error("FindWindow failed for '%s/%s'\n",
			pclass ? pclass : "",
			pname ? pname : "");
		return -1;
	}
	//
	GetWindowText(hWnd, wndname, sizeof(wndname));
	dw = GetSystemMetrics(SM_CXSCREEN);
	dh = GetSystemMetrics(SM_CYSCREEN);
	//
	ga_error("Found window (0x%08x) :%s%s%s%s\n", hWnd,
		pclass ? " class=" : "",
		pclass ? pclass : "",
		pname ? " name=" : "",
		pname ? pname : "");
	//设置子窗口置顶
	if(SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW) == 0) {
		ga_error("SetWindowPos failed.\n");
		return -1;
	}
	if(GetClientRect(hWnd, &client) == 0) {
		ga_error("GetClientRect failed.\n");
		return -1;
	}
	if(SetForegroundWindow(hWnd) == 0) {
		ga_error("SetForegroundWindow failed.\n");
	}
	//
	lt.x = client.left;
	lt.y = client.top;
	rb.x = client.right-1;
	rb.y = client.bottom-1;
	//
	if(ClientToScreen(hWnd, &lt) == 0
	|| ClientToScreen(hWnd, &rb) == 0) {
		ga_error("Map from client coordinate to screen coordinate failed.\n");
		return -1;
	}
	//
	rect->left = lt.x;
	rect->top = lt.y;
	rect->right = rb.x;
	rect->bottom = rb.y;
	// size check: multiples of 2?
	if((rect->right - rect->left + 1) % 2 != 0)
		rect->left--;
	if((rect->bottom - rect->top + 1) % 2 != 0)
		rect->top--;
	//
	if(rect->left < 0 || rect->top < 0 || rect->right >= dw || rect->bottom >= dh) {
		ga_error("Invalid window: (%d,%d)-(%d,%d) w=%d h=%d (screen dimension = %dx%d).\n",
			rect->left, rect->top, rect->right, rect->bottom,
			rect->right - rect->left + 1,
			rect->bottom - rect->top + 1);
		return -1;
	}
	//
	*prect = rect;
	return 1;
}
#elif defined(__APPLE__) || defined(ANDROID)
int
ga_crop_window(struct gaRect *rect, struct gaRect **prect) {
	// XXX: implement find window for Apple
	*prect = NULL;
	return 0;
}
#else /* X11 */
Window
FindWindowX(Display *dpy, Window top, const char *name) {
	Window *children, dummy;
	unsigned int i, nchildren;
	Window w = 0;
	char *window_name;

	if(XFetchName(dpy, top, &window_name) && !strcmp(window_name, name)) {
		return(top);
	}

	if(!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
		return(0);

	for(i = 0; i < nchildren; i++) {
		w = FindWindowX(dpy, children[i], name);
		if (w) {
			break;
		}
	}

	if (children)
		XFree ((char *)children);

	return(w);
}
Esempio n. 15
0
string window_get_caption()
{
	char *caption;
	XFetchName(disp,win,&caption);
	string r=caption;
	return r;
}
Esempio n. 16
0
void getwindowname(Window win, unsigned int stext) {
    char *win_name;

    if(XFetchName(dis, win, &win_name) != 0) strncpy(winname, win_name, 100);
    else winname[0] = '\0';
    if(win_name) XFree(win_name);
    if(stext == 0) status_text(winname);
}
Esempio n. 17
0
void print_window_information ( Window w, void* data )
{
	char* name; XFetchName ( dp, w, &name );
	
	printf("\tWindow 0x%x / '%s'\n", w, name );
	
	return;
}
Esempio n. 18
0
Window find_window(Window top,char *name)
{
  char *wname,*iname;
  XClassHint xch;
  Window *children,foo;
  int revert_to_return;
  unsigned int nc;
  if (!strcmp(active_window_name,name)){
    XGetInputFocus(dpy, &foo, &revert_to_return);
    return(foo);
  }
  /* First the base case */
  if (XFetchName(dpy,top,&wname)){
    if (!strncmp(wname,name,strlen(name)))  {
      XFree(wname);
      debugprintf("found it by wname %x \n",top);
      return(top);  /* found it! */
    };
    XFree(wname);
  };

  if(XGetIconName(dpy,top,&iname)){
    if (!strncmp(iname,name,strlen(name)))  {
      XFree(iname);
      debugprintf("found it by iname %x \n",top);
      return(top);  /* found it! */
    };
    XFree(iname);
  };

  if(XGetClassHint(dpy,top,&xch))  {
    if(!strcmp(xch.res_class,name))  {
      XFree(xch.res_name); XFree(xch.res_class);
      debugprintf("res_class '%s' res_name '%s' %x \n", xch.res_class,xch.res_name,top);
      return(top);  /* found it! */
    };
    if(!strcmp(xch.res_name,name))  {
      XFree(xch.res_name); XFree(xch.res_class);
      debugprintf("res_class '%s' res_name '%s' %x \n", xch.res_class,xch.res_name,top);
      return(top);  /* found it! */
    };
    XFree(xch.res_name); XFree(xch.res_class);
  };

  if(!XQueryTree(dpy,top,&foo,&foo,&children,&nc) || children==NULL) {
    return(0);  /* no more windows here */
  };

  /* check all the sub windows */
  for(;nc>0;nc--)  {
    top = find_window(children[nc-1],name);
    if(top) break;  /* we found it somewhere */
  };
  if(children!=NULL) XFree(children);
  return(top);
}
Esempio n. 19
0
QString QxtWindowSystem::windowTitle(WId window)
{
    QString name;
    char* str = 0;
    if (XFetchName(QX11Info::display(), window, &str))
        name = QString::fromLatin1(str);
    if (str)
        XFree(str);
    return name;
}
Esempio n. 20
0
void print_xwindow(X11Data *x11data)
{
    char* name;
    int status = XFetchName(x11data->display, x11data->window, &name);
    if (status >= Success)
    {
        printf("0x%lx  %s\n", x11data->window, name);
    }
    XFree(name);
}
Esempio n. 21
0
// ===== 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;
}
Esempio n. 22
0
std::string XLibWrapper::getWindowName( Window window )
{
	char* buffer;
	if( !XFetchName(_display,window,&buffer) )
		return std::string().c_str();

	std::string windowName(buffer);
	XFree( buffer );

	return windowName;
}
Esempio n. 23
0
static void
set_title (const char *str)
{
  char *name;
  if (XFetchName (Xdisplay, TermWin.parent, &name))
    name = NULL;
  if (name == NULL || strcmp (name, str))
    XStoreName (Xdisplay, TermWin.parent, str);
  if (name)
    XFree (name);
}
Esempio n. 24
0
// i got the idea for this from taskbar-plugin of LXPanel - so credits fly out :)
QString XfitMan::getWindowTitle(Window _wid) const
{
    QString name = "";
    //first try the modern net-wm ones
    unsigned long length;
    unsigned char *data = nullptr;
    
    Atom utf8Atom = atom("UTF8_STRING");

    if (getWindowProperty(_wid, atom("_NET_WM_VISIBLE_NAME"), utf8Atom, &length, &data))
    {
        name = QString::fromUtf8((char*) data);
        XFree(data);

    }

    if (name.isEmpty())
    {
        if (getWindowProperty(_wid, atom("_NET_WM_NAME"), utf8Atom, &length, &data))
        {
            name = QString::fromUtf8((char*) data);
            XFree(data);
        }
    }

    if (name.isEmpty())
    {
        if (getWindowProperty(_wid, atom("XA_WM_NAME"), XA_STRING, &length, &data))
        {
            name = (char*) data;
            XFree(data);
        }
    }

    if (name.isEmpty())
    {
        Status ok = XFetchName(QX11Info::display(), _wid, (char**) &data);
        name = QString((char*) data);
        if (0 != ok) XFree(data);
    }

    if (name.isEmpty())
    {
        XTextProperty prop;
        if (XGetWMName(QX11Info::display(), _wid, &prop))
        {
            name = QString::fromUtf8((char*) prop.value);
            XFree(prop.value);
        }
    }

    return name;
}
Esempio n. 25
0
char* OsWindow::title()
{
	static char title[1024];

	char* tmp_title;
	XFetchName(m_x11_display, m_x11_window, &tmp_title);

	string::strncpy(title, tmp_title, 1024);
	XFree(tmp_title);

	return title;
}
Esempio n. 26
0
const char *debX11_win(Window w) {
    Status res;
    char out[64], buf[64];
    char *name;

    if (w == None)
        return "None";
    //if (!(res = XGetIconName(display, w, &name)) || name == NULL)
    if (!(res = XFetchName(display, w, &name)) || name == NULL)
        sprintf(name = buf, "0x%lX %d", w, res);

    sprintf(out, "win(%.12s)", name);
    return strdup(out);
}
Esempio n. 27
0
/*Function gets handler for visible window with specified name
 * Parameters: full window name
 * Returns window handler or ERROR_HANDLER if fails*/
Window getWindowHandler(char* window_name) {
    Display  *display;
    Atom     actual_type;
    int      actual_format;
    long     nitems;
    long     bytes;
    unsigned long     *data;
    int      status;
    int i;
    char*name;
    Window res=ERROR_HANDLER;
    /*Connecting to X server*/
    display = XOpenDisplay(NULL);
    if (!display) {
        fprintf(stderr,"Error: Unable to connect to display\n");
        return ERROR_HANDLER;
    }
    /*Fetching all windows as a property of window manager*/
    status = XGetWindowProperty(
                 display,
                 RootWindow(display, 0),
                 XInternAtom(display, "_NET_CLIENT_LIST_STACKING", True),
                 0,
                 (~0L),
                 False,
                 AnyPropertyType,
                 &actual_type,
                 &actual_format,
                 &nitems,
                 &bytes,
                 (unsigned char**)&data);
    if (status != Success) {
        fprintf(stderr, "Error: Getting visible windows was not successful\n");
        return ERROR_HANDLER;
    }
    /*Looking for window with the specified name*/
    for (i=0; i < nitems; i++) {
        XFetchName(display,data[i],&name);
        if((name!=NULL)&&(strcmp(name,window_name)==0)) {
            res=data[i];
        }
        free(name);
    }
    /*Finishing*/
    free(data);
    XCloseDisplay(display);
    return res;

}
Esempio n. 28
0
static gchar *window_get_name_fallback(RoccatWindowMonitor *monitor, Window window) {
	RoccatWindowMonitorPrivate *priv = monitor->priv;
	char *name;
	gchar *result;

	if (window == None)
		return NULL;

	if (XFetchName(priv->display, window, &name) && name) {
		result = g_strdup(name);
		XFree(name);
		return result;
	}
	return NULL;
}
Esempio n. 29
0
Window FindWindow(char* szWindowToFind)
{
    Display *display = XOpenDisplay (NULL);
    int screen = DefaultScreen (display);
    XSetErrorHandler(ErrorHandler);
    Window rootWindow = RootWindow (display, screen);   
    Window wSearchedWindow = SearchWindow(szWindowToFind, 0, display, 
					  rootWindow, 0, 0);
    char* win_name;
    if (XFetchName(display, wSearchedWindow, &win_name))
    {
        printf("Found: %s\n", win_name);
    }
    XCloseDisplay (display);
    return wSearchedWindow;
}
Esempio n. 30
0
char* _gfx_platform_window_get_name(

		GFX_PlatformWindow handle)
{
	/* Check if it has a name */
	char* buff;
	XFetchName(_gfx_x11.display, GFX_VOID_TO_UINT(handle), &buff);
	if(!buff) return NULL;

	/* Copy to client side memory */
	char* name = malloc(strlen(buff) + 1);
	strcpy(name, buff);

	XFree(buff);

	return name;
}