void InitializeX11(uint16_t x_off, uint16_t y_off, uint16_t *w, uint16_t *h){
	printf("Loading X11 Module\n");

	dpy = XOpenDisplay("");

	default_src = XDefaultScreen(dpy);
	CaptureWin = Select_Window();
	XGetWindowAttributes(dpy, CaptureWin, &gwa);
	*w = gwa.width;
	*h = gwa.height;
#ifdef X11_USE_XSHM_
	use_shm = XShmQueryExtension(dpy);
	if(use_shm) {
		printf("XShmQueryExtension(dpy);\n");
		image = XShmCreateImage(dpy,
					DefaultVisual(dpy, default_src),
					DefaultDepth(dpy, default_src),
					ZPixmap,
					NULL,
					&shminfo,
					gwa.width, gwa.height);
		shminfo.shmid = shmget(	IPC_PRIVATE,
					image->bytes_per_line * image->height,
					IPC_CREAT|0777);
		if(shminfo.shmid == -1) {
			printf("shminfo.shmid == -1\n");
			return;
		}
		shminfo.shmaddr = image->data = (char*) shmat(shminfo.shmid, 0, 0);
		shminfo.readOnly = False;

		if (!XShmAttach(dpy, &shminfo)) {
			printf("!XShmAttach(dpy, &shminfo)\n");
			return;
		}
	}
	else{
#endif /*X11_USE_XSHM_*/
		image = XGetImage(dpy, CaptureWin,
				  x_off,y_off,
				  gwa.width,gwa.height,
				  AllPlanes, ZPixmap);
#ifdef X11_USE_XSHM_
	}
#endif /*X11_USE_XSHM_*/
	printf("X11 Module Running\n");
}
Ejemplo n.º 2
0
int action_window_str (Display *disp, char mode) {/*{{{*/
    Window activate = 0;
    Window *client_list;
    unsigned long client_list_size;
    unsigned int i;
    
    if (strcmp(SELECT_WINDOW_MAGIC, options.param_window) == 0) {
        activate = Select_Window(disp);
        if (activate) {
            return action_window(disp, activate, mode);
        }
        else {
            return EXIT_FAILURE;
        }
    }
    if (strcmp(ACTIVE_WINDOW_MAGIC, options.param_window) == 0) {
        activate = get_active_window(disp);
        if (activate)
        {
            return action_window(disp, activate, mode);
        }
        else
        {
            return EXIT_FAILURE;
        }
    }
    else {
        if ((client_list = get_client_list(disp, &client_list_size)) == NULL) {
            return EXIT_FAILURE; 
        }
        
        for (i = 0; i < client_list_size / sizeof(Window); i++) {
 			gchar *match_utf8;
 			if (options.show_class) {
 	            match_utf8 = get_window_class(disp, client_list[i]); /* UTF8 */
 			}
 			else {
 				match_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
 			}
            if (match_utf8) {
                gchar *match;
                gchar *match_cf;
                gchar *match_utf8_cf = NULL;
                if (envir_utf8) {
                    match = g_strdup(options.param_window);
                    match_cf = g_utf8_casefold(options.param_window, -1);
                }
                else {
                    if (! (match = g_locale_to_utf8(options.param_window, -1, NULL, NULL, NULL))) {
                        match = g_strdup(options.param_window);
                    }
                    match_cf = g_utf8_casefold(match, -1);
                }
                
                if (!match || !match_cf) {
                    continue;
                }

                match_utf8_cf = g_utf8_casefold(match_utf8, -1);

                if ((options.full_window_title_match && strcmp(match_utf8, match) == 0) ||
                        (!options.full_window_title_match && strstr(match_utf8_cf, match_cf))) {
                    activate = client_list[i];
                    g_free(match);
                    g_free(match_cf);
                    g_free(match_utf8);
                    g_free(match_utf8_cf);
                    break;
                }
                g_free(match);
                g_free(match_cf);
                g_free(match_utf8);
                g_free(match_utf8_cf);
            }
        }
        g_free(client_list);

        if (activate) {
            return action_window(disp, activate, mode);
        }
        else {
            return EXIT_FAILURE;
        }
    }
}/*}}}*/