コード例 #1
0
ファイル: VideoPinsAPI.cpp プロジェクト: Steshov/VideoPins
static Window action_window_str (Display *disp, gchar *class_name, gchar *title_name) {/*{{{*/
    Window activate = 0;
    Window *client_list;
    unsigned long client_list_size;
    int i;
    
    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 *r_class_name = get_window_class(disp, client_list[i]);
            gchar *r_title_name = get_window_title(disp, client_list[i]);

            if(strcmp(r_class_name, class_name) == 0 &&
                strcmp(r_title_name, title_name) == 0)
            {
                activate = client_list[i];
                g_free(r_class_name);
                g_free(r_title_name);
                break;
            }
    }
    g_free(client_list);

    if (activate) {
        return activate;
        //action_window(disp, activate);
    }
    else {
        return EXIT_FAILURE;
    }
}/*}}}*/
コード例 #2
0
ファイル: main.c プロジェクト: amkhlv/wmjump
static void get_list_from_wm(   Display *disp, 
                                Window *client_list,
                                unsigned long client_list_size,
                                unsigned int *number_of_buttons,
                                int *window_number,
                                gchar **title_of_button,
                                gchar **name_of_style,
                                int groupnumber,
                                Window *win_we_leave,
                                gboolean  *win_we_leave_is_blacklisted) {

    /* Look up which window classes are blacklisted: */
    gchar *blacklist;
    gchar *file_blacklist_in_home_dir = g_strconcat(home,"/.wmjump/",BLACKLISTFILE,NULL) ;
    if ( g_file_test(file_blacklist_in_home_dir, G_FILE_TEST_EXISTS) )
        {
        g_file_get_contents( file_blacklist_in_home_dir , &blacklist,NULL,NULL);
        }
    else
        {
        g_file_get_contents( g_strconcat("/etc/wmjump/",BLACKLISTFILE,NULL) , &blacklist,NULL,NULL);
        }
    g_free(file_blacklist_in_home_dir); file_blacklist_in_home_dir = NULL ;

    unsigned long *desktop_viewport = NULL;
    *win_we_leave_is_blacklisted = TRUE ; 
    *number_of_buttons = 0;
    Window active_window = window_now_active(disp);
    *win_we_leave = active_window;
    p_verb("active window = %x\n",(int)active_window);
    /* Check if active_window is one from the client list: */
    gboolean active_window_is_strange = TRUE ;
    unsigned int i ;
    for (i = 0; i < client_list_size / sizeof(Window); i++) {
        if (active_window == client_list[i]) { active_window_is_strange = FALSE ; break ; }
        }
    if (active_window_is_strange) { p_verbose("wmjump: *** STRANGE ACTIVE WINDOW: win=%x ***\n", (int)active_window); }
    else {
        gchar *itemclass = get_window_class(disp,active_window);
        gchar *class_is_blacklisted = g_strrstr(g_strconcat("\n",blacklist,"\n",NULL),
                                                g_strconcat("\n",itemclass,"\n",NULL));
        if (class_is_blacklisted == NULL) { *win_we_leave_is_blacklisted = FALSE ; } 
         }
    
    for (i = 0; i < client_list_size / sizeof(Window); i++) {
        gchar *title_utf8 = get_window_title(disp, client_list[i]); 
        gchar *title_out = get_output_str(title_utf8, TRUE);
        
        if (verbose) printf("%d %s\n", i, title_out ? title_out : "N/A");

        gchar *itemclass = get_window_class(disp,client_list[i]);

        if (verbose) printf("window class: %s WINDOW: %x\n",itemclass,(gint)client_list[i]);
        if (verbose) printf("_______________________\n");

        gchar *class_is_blacklisted = g_strrstr(g_strconcat("\n",blacklist,"\n",NULL),
                                                g_strconcat("\n",itemclass,"\n",NULL));

        if (class_is_blacklisted == NULL) {
            unsigned long *desktop;
        
            if ((desktop = (unsigned long *)get_property(disp, client_list[i],
                    XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
                if ((desktop = (unsigned long *)get_property(disp, client_list[i],
                        XA_CARDINAL, "_WIN_WORKSPACE", NULL)) == NULL) {
                    printf("wmjump: Cannot find desktop ID of the window.\n"); }}

            gboolean in_scope;

            if (do_check_desktop) {
                unsigned long fake_desktop = 9999;
                unsigned long *now_desktop = &fake_desktop;
                if (given_groupnumber) {
                    unsigned long uldn = (unsigned long)groupnumber;
                    now_desktop = &uldn;
                } else {
                    if (active_window_is_strange) {
                        p_verbose("wmjump: *** COULD NOT DETECT ACTIVE WINDOW ***\n");
                    } else {
                        if ((now_desktop = (unsigned long *)get_property(
                                 disp,
                                 active_window,
                                 XA_CARDINAL,
                                 "_NET_WM_DESKTOP",
                                 NULL
                                 )) == NULL) {
                            if ((now_desktop = (unsigned long *)get_property(
                                     disp,
                                     active_window,
                                     XA_CARDINAL,
                                     "_WIN_WORKSPACE",
                                     NULL
                                     )) == NULL) {
                                printf("wmjump: Cannot find desktop ID of the window.\n");
                            }
                        }
                    }
                }
                in_scope = (*desktop == *now_desktop);
            } else {in_scope = True;}

            if ( in_scope || !current_only ) {

            int n = *number_of_buttons;
            window_number[n] = i;

            gchar desk_id[12]; /* xx,yy perhaps use some unicode instead of comma */
            sprintf(desk_id, "%d", (int)*desktop+1);
            gchar *title_tr;
            title_tr = truncate_title(title_out);
            gchar *itemtitle ;
            /* Now want to set the label string; put asterisk if active */
            gchar *lttr_bf;
            if (boldface) { lttr_bf = g_strconcat("<span weight=\"bold\">", lttr[n],
                                                  "</span>", NULL); }
            else    { lttr_bf = lttr[n]; }
            if ( client_list[i] == active_window ) {
                gchar asterisk[8];
                sprintf(asterisk, "%lc", CHECK);
                if (boldface) {
                    itemtitle = g_strconcat("<big>", asterisk, " ", desk_id," (",lttr_bf,") ",
                        "<u>",title_tr,"</u>"," (",lttr_bf,") ", asterisk, "</big>", NULL);
                                             }
                else { itemtitle = g_strconcat(asterisk, " ", desk_id," (",lttr_bf,") ",
                                        title_tr," (",lttr_bf,") ", asterisk, NULL);
                      }
            } else { 
                itemtitle = g_strconcat(desk_id," (",lttr_bf,") ",
                                        title_tr," (",lttr_bf,") ",NULL); 
            }    
            title_of_button[n]=itemtitle; 
            name_of_style[n] = itemclass ;

            (*number_of_buttons)++  ;
            if ( *number_of_buttons == g_strv_length(lttr) ) break;
            } 
            g_free(desktop);  desktop = NULL ;
            }
    }
    title_of_button[*number_of_buttons]=NULL;
    name_of_style[*number_of_buttons]=NULL;

    g_free(blacklist); blacklist = NULL ;
    g_free(desktop_viewport); desktop_viewport = NULL ;
}
コード例 #3
0
ファイル: wmctrl.c プロジェクト: amkhlv/wmjump
int list_windows (Display *disp) {/*{{{*/
    Window *client_list;
    unsigned long client_list_size;
    unsigned int i;
    int max_client_machine_len = 0;
    
    if ((client_list = get_client_list(disp, &client_list_size)) == NULL) {
        return EXIT_FAILURE; 
    }
    
    /* find the longest client_machine name */
    for (i = 0; i < client_list_size / sizeof(Window); i++) {
        gchar *client_machine;
        if ((client_machine = get_property(disp, client_list[i],
                XA_STRING, "WM_CLIENT_MACHINE", NULL))) {
            max_client_machine_len = strlen(client_machine);    
        }
        g_free(client_machine);
    }
    
    /* print the list */
    for (i = 0; i < client_list_size / sizeof(Window); i++) {
        gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
        gchar *title_out = get_output_str(title_utf8, TRUE);
        gchar *client_machine;
        gchar *class_out = get_window_class(disp, client_list[i]); /* UTF8 */
        unsigned long *pid;
        unsigned long *desktop;
        int x, y, junkx, junky;
        unsigned int wwidth, wheight, bw, depth;
        Window junkroot;

        /* desktop ID */
        if ((desktop = (unsigned long *)get_property(disp, client_list[i],
                XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
            desktop = (unsigned long *)get_property(disp, client_list[i],
                    XA_CARDINAL, "_WIN_WORKSPACE", NULL);
        }

        /* client machine */
        client_machine = get_property(disp, client_list[i],
                XA_STRING, "WM_CLIENT_MACHINE", NULL);
       
        /* pid */
        pid = (unsigned long *)get_property(disp, client_list[i],
                XA_CARDINAL, "_NET_WM_PID", NULL);

	    /* geometry */
        XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky,
                          &wwidth, &wheight, &bw, &depth);
        XTranslateCoordinates (disp, client_list[i], junkroot, junkx, junky,
                               &x, &y, &junkroot);
      
        /* special desktop ID -1 means "all desktops", so we 
           have to convert the desktop value to signed long */
        printf("0x%.8lx %2ld", client_list[i], 
                desktop ? (signed long)*desktop : 0);
        if (options.show_pid) {
           printf(" %-6lu", pid ? *pid : 0);
        }
        if (options.show_geometry) {
           printf(" %-4d %-4d %-4d %-4d", x, y, wwidth, wheight);
        }
		if (options.show_class) {
		   printf(" %-20s ", class_out ? class_out : "N/A");
		}

        printf(" %*s %s\n",
              max_client_machine_len,
              client_machine ? client_machine : "N/A",
              title_out ? title_out : "N/A"
		);
        g_free(title_utf8);
        g_free(title_out);
        g_free(desktop);
        g_free(client_machine);
        g_free(class_out);
        g_free(pid);
    }
    g_free(client_list);
   
    return EXIT_SUCCESS;
}/*}}}*/
コード例 #4
0
ファイル: wmctrl.c プロジェクト: amkhlv/wmjump
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;
        }
    }
}/*}}}*/
コード例 #5
0
ファイル: winManage.c プロジェクト: cherry-wb/quietheart
void print_win_info(Display *disp, Window *win)
{
	gchar *title_utf8 = get_window_title(disp, *win); /* UTF8 */
	gchar *title_out = get_output_str(title_utf8, TRUE);

	gchar *client_machine;
	gchar *class_out = get_window_class(disp, *win); /* UTF8 */

	unsigned long *pid;
	unsigned long *desktop;
	int x, y, junkx, junky;
	unsigned int wwidth, wheight, bw, depth;
	Window junkroot;

	/* desktop ID */
	if ((desktop = (unsigned long *)get_property(disp, *win,
					XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
		desktop = (unsigned long *)get_property(disp, *win,
				XA_CARDINAL, "_WIN_WORKSPACE", NULL);
	}

	/* client machine */
	client_machine = get_property(disp, *win,
			XA_STRING, "WM_CLIENT_MACHINE", NULL);

	/* pid */
	pid = (unsigned long *)get_property(disp, *win,
			XA_CARDINAL, "_NET_WM_PID", NULL);

	/* geometry */
	/*        XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky,
			  &wwidth, &wheight, &bw, &depth);
			  XTranslateCoordinates (disp, client_list[i], junkroot, junkx, junky,
			  &x, &y, &junkroot);*/

	/* special desktop ID -1 means "all desktops", so we 
	   have to convert the desktop value to signed long */
	printf("------\n");
	printf("WinID:");
	printf("0x%.8lx\n", *win); 
	printf("DesktopID:");
	printf("%2ld\n",
			desktop ? (signed long)*desktop : 0);

	/*show pid of the window*/
	printf("PID:");
	printf(" %-6lu\n", pid ? *pid : 0);
	/*        if (options.show_geometry) {
			  printf(" %-4d %-4d %-4d %-4d", x, y, wwidth, wheight);
			  }*/
	/*show class of the window*/
	printf("WinClass:");
	printf(" %-20s\n", class_out ? class_out : "N/A");

	printf("client_machine:");
	printf("%s\n",
			client_machine ? client_machine : "N/A"
		  );
	printf("WinTitle:");
	printf(" %s\n",
			title_out ? title_out : "N/A");
	printf("------\n");
	g_free(title_utf8);
	g_free(title_out);
	g_free(desktop);
	g_free(client_machine);
	g_free(class_out);
	g_free(pid);
}