Exemplo n.º 1
0
XCTRL_API char* get_desktop_name(Display *disp, int desknum, Bool force_utf8)
{
  char *name_list = NULL;
  ulong name_list_size = 0;
  char *name = NULL;
  Bool names_are_utf8 = True;
  Window root = DefRootWin;
  char*rv=NULL;
  if (desknum<0) { return NULL; }
  if (force_utf8) {
    name_list = get_prop(disp, root, GetUTF8Atom(), "_NET_DESKTOP_NAMES", &name_list_size);
  }
  if (!name_list) {
    names_are_utf8 = False;
    name_list = get_prop(disp, root, XA_STRING, "_WIN_WORKSPACE_NAMES", &name_list_size);
  }
  if (name_list) {
    if (desknum>0) { 
      int id=1;
      char*p=name_list;
      do {
        p=strchr(p,'\0')+1;
        if (id==desknum) {
          name=p;
          break;
        }
        id++;
      } while (p<(name_list+name_list_size));
    } else { name=name_list; }
    if (name && *name) { rv = get_output_str(name, names_are_utf8); }
    free(name_list);
  }
  return rv;
}
Exemplo n.º 2
0
static char* get_prop_utf8(Display *disp, Window win, const char*what)
{
  Bool name_is_utf8 = True;
  char*result=NULL;
  char*tmp=get_prop(disp, win, GetUTF8Atom(), what, NULL);
  if (!tmp) {
    name_is_utf8 = False;
    result = get_prop(disp, win, XA_STRING, what, NULL);
  }
  result=get_output_str(tmp, name_is_utf8);
  sfree(tmp);
  return result;
}
Exemplo n.º 3
0
gchar *get_title_by_window(Display *disp, Window win)
{
	gchar *title_utf8 = get_window_title(disp, win); /* UTF8 */
#if MY_DEBUG_OUTPUT == 1
	g_print("after get_window_title**\n");
#endif
	gchar *title_out = get_output_str(title_utf8, TRUE);
#if MY_DEBUG_OUTPUT == 1
	g_print(title_out);
	g_print("*******title_out is ok??\n");
#endif
	g_free(title_utf8);
	return title_out;
}
Exemplo n.º 4
0
int close_win_by_title(gchar *title)
{
    Window *client_list;
    unsigned long client_list_size;
	int count;
    int i;
	Display *disp;

	setlocale(LC_ALL, "");
	init_charset();/*lkadd*/
	if (! (disp = XOpenDisplay(NULL)))
	{
		fputs("Cannot open display.\n", stderr);
		return 1;
	}/*打开显示*/
    if((client_list = get_client_list(disp, &client_list_size)) == NULL)
	{
        return EXIT_FAILURE; 
    } 

	count = client_list_size / sizeof(Window);
    for (i = 0; i < count; i++)
	{
        gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
        gchar *title_out = get_output_str(title_utf8, TRUE);

		if(g_strcasecmp(title, title_out) == 0)
		{
			close_window(disp, client_list[i]);
			break;
		}
        g_free(title_utf8);
        g_free(title_out);
    }
    g_free(client_list);
	XCloseDisplay(disp);

	if(i >= count)
	{
		return EXIT_SUCCESS;
	}
	else
	{
#if MY_DEBUG_OUTPUT == 1
		g_print("cann't find the window with title:%s \n", title);
#endif
		return 1;
	}
}
Exemplo n.º 5
0
/*
 * Return the name of the window manager.
 * NULL on error.
 */
static gchar *wm_get_name(Display *disp)
{
    Window *sup_window = NULL;
    gchar *wm_name = NULL;
    gboolean name_is_utf8 = TRUE;
    gchar *name_out;
    
    if(!(sup_window = (Window *)get_property(disp, DefaultRootWindow(disp), XA_WINDOW, "_NET_SUPPORTING_WM_CHECK", NULL))) 
        if(!(sup_window = (Window *)get_property(disp, DefaultRootWindow(disp), XA_CARDINAL, "_WIN_SUPPORTING_WM_CHECK", NULL)))
            return NULL;

    /* WM_NAME */
    if(!(wm_name = get_property(disp, *sup_window, XInternAtom(disp, "UTF8_STRING", False), "_NET_WM_NAME", NULL)))
        return NULL;

    name_out = get_output_str(wm_name, name_is_utf8);
  
    g_free(sup_window);
    g_free(wm_name);
    
    return name_out;
}
Exemplo n.º 6
0
static int wm_info(Display *disp) {
    Window *sup_window = NULL;
    gchar *wm_name = NULL;
    gchar *wm_class = NULL;
    unsigned long *wm_pid = NULL;
    unsigned long *showing_desktop = NULL;
    gboolean name_is_utf8 = TRUE;
    gchar *name_out;
    gchar *class_out;
    
    if(!(sup_window =(Window *)get_property(disp, DefaultRootWindow(disp),
                                            XA_WINDOW, 
                                            "_NET_SUPPORTING_WM_CHECK", NULL))) {
        if(!(sup_window =(Window *)get_property(disp, DefaultRootWindow(disp),
                                                XA_CARDINAL, 
                                                "_WIN_SUPPORTING_WM_CHECK", NULL))) {
            fputs("Cannot get window manager info properties.\n"
                  "(_NET_SUPPORTING_WM_CHECK or _WIN_SUPPORTING_WM_CHECK)\n", stderr);
            return EXIT_FAILURE;
        }
    }

    /* WM_NAME */
    if(!(wm_name = get_property(disp, *sup_window,
            XInternAtom(disp, "UTF8_STRING", False), "_NET_WM_NAME", NULL))) {
        name_is_utf8 = FALSE;
        if(!(wm_name = get_property(disp, *sup_window,
                XA_STRING, "_NET_WM_NAME", NULL))) {
            p_verbose("Cannot get name of the window manager (_NET_WM_NAME).\n");
        }
    }
    name_out = get_output_str(wm_name, name_is_utf8);
  
    /* WM_CLASS */
    if(!(wm_class = get_property(disp, *sup_window,
            XInternAtom(disp, "UTF8_STRING", False), "WM_CLASS", NULL))) {
        name_is_utf8 = FALSE;
        if(!(wm_class = get_property(disp, *sup_window,
                XA_STRING, "WM_CLASS", NULL))) {
            p_verbose("Cannot get class of the window manager (WM_CLASS).\n");
        }
    }
    class_out = get_output_str(wm_class, name_is_utf8);
  

    /* WM_PID */
    if(!(wm_pid = (unsigned long *)get_property(disp, *sup_window,
                    XA_CARDINAL, "_NET_WM_PID", NULL))) {
        p_verbose("Cannot get pid of the window manager (_NET_WM_PID).\n");
    }
    
    /* _NET_SHOWING_DESKTOP */
    if(!(showing_desktop = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                    XA_CARDINAL, "_NET_SHOWING_DESKTOP", NULL))) {
        p_verbose("Cannot get the _NET_SHOWING_DESKTOP property.\n");
    }
    
    /* print out the info */
    printf("Name: %s\n", name_out ? name_out : "N/A");
    printf("Class: %s\n", class_out ? class_out : "N/A");
    
    if(wm_pid) 
        printf("PID: %lu\n", *wm_pid);
    else
        printf("PID: N/A\n");
    
    if(showing_desktop) {
        printf("Window manager's \"showing the desktop\" mode: %s\n",
                *showing_desktop == 1 ? "ON" : "OFF");
    }
    else {
        printf("Window manager's \"showing the desktop\" mode: N/A\n");
    }
    
    g_free(name_out);
    g_free(sup_window);
    g_free(wm_name);
    g_free(wm_class);
    g_free(wm_pid);
    g_free(showing_desktop);
    
    return EXIT_SUCCESS;
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: 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 ;
}
Exemplo n.º 8
0
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;
}/*}}}*/
Exemplo n.º 9
0
int list_desktops (Display *disp) {/*{{{*/
    unsigned long *num_desktops = NULL;
    unsigned long *cur_desktop = NULL;
    unsigned long desktop_list_size = 0;
    unsigned long *desktop_geometry = NULL;
    unsigned long desktop_geometry_size = 0;
    gchar **desktop_geometry_str = NULL;
    unsigned long *desktop_viewport = NULL;
    unsigned long desktop_viewport_size = 0;
    gchar **desktop_viewport_str = NULL;
    unsigned long *desktop_workarea = NULL;
    unsigned long desktop_workarea_size = 0;
    gchar **desktop_workarea_str = NULL;
    gchar *list = NULL;
    unsigned int i;
    unsigned int id;
    Window root = DefaultRootWindow(disp);
    int ret = EXIT_FAILURE;
    gchar **names = NULL;
    gboolean names_are_utf8 = TRUE;
    
    if (! (num_desktops = (unsigned long *)get_property(disp, root,
            XA_CARDINAL, "_NET_NUMBER_OF_DESKTOPS", NULL))) {
        if (! (num_desktops = (unsigned long *)get_property(disp, root,
                XA_CARDINAL, "_WIN_WORKSPACE_COUNT", NULL))) {
            fputs("Cannot get number of desktops properties. "
                  "(_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT)"
                  "\n", stderr);
            goto cleanup;
        }
    }
    
    if (! (cur_desktop = (unsigned long *)get_property(disp, root,
            XA_CARDINAL, "_NET_CURRENT_DESKTOP", NULL))) {
        if (! (cur_desktop = (unsigned long *)get_property(disp, root,
                XA_CARDINAL, "_WIN_WORKSPACE", NULL))) {
            fputs("Cannot get current desktop properties. "
                  "(_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)"
                  "\n", stderr);
            goto cleanup;
        }
    }

    if (options.wa_desktop_titles_invalid_utf8 || 
            (list = get_property(disp, root, 
            XInternAtom(disp, "UTF8_STRING", False), 
            "_NET_DESKTOP_NAMES", &desktop_list_size)) == NULL) {
        names_are_utf8 = FALSE;
        if ((list = get_property(disp, root, 
            XA_STRING, 
            "_WIN_WORKSPACE_NAMES", &desktop_list_size)) == NULL) {
            p_verbose("Cannot get desktop names properties. "
                  "(_NET_DESKTOP_NAMES or _WIN_WORKSPACE_NAMES)"
                  "\n");
            /* ignore the error - list the desktops without names */
        }
    }
 
    /* common size of all desktops */
    if (! (desktop_geometry = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                    XA_CARDINAL, "_NET_DESKTOP_GEOMETRY", &desktop_geometry_size))) {
        p_verbose("Cannot get common size of all desktops (_NET_DESKTOP_GEOMETRY).\n");
    }
     
    /* desktop viewport */
    if (! (desktop_viewport = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                    XA_CARDINAL, "_NET_DESKTOP_VIEWPORT", &desktop_viewport_size))) {
        p_verbose("Cannot get common size of all desktops (_NET_DESKTOP_VIEWPORT).\n");
    }
     
    /* desktop workarea */
    if (! (desktop_workarea = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                    XA_CARDINAL, "_NET_WORKAREA", &desktop_workarea_size))) {
        if (! (desktop_workarea = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                        XA_CARDINAL, "_WIN_WORKAREA", &desktop_workarea_size))) {
            p_verbose("Cannot get _NET_WORKAREA property.\n");
        }
    }
     
    /* prepare the array of desktop names */
    names = g_malloc0(*num_desktops * sizeof(char *));
    if (list) {
        id = 0;
        names[id++] = list;
        for (i = 0; i < desktop_list_size; i++) {
            if (list[i] == '\0') {
                if (id >= *num_desktops) {
                    break;
                }
                names[id++] = list + i + 1;
            }
        }
    }

    /* prepare desktop geometry strings */
    desktop_geometry_str = g_malloc0((*num_desktops + 1) * sizeof(char *));
    if (desktop_geometry && desktop_geometry_size > 0) {
        if (desktop_geometry_size == 2 * sizeof(*desktop_geometry)) {
            /* only one value - use it for all desktops */
            p_verbose("WM provides _NET_DESKTOP_GEOMETRY value common for all desktops.\n");
            for (i = 0; i < *num_desktops; i++) {
                desktop_geometry_str[i] = g_strdup_printf("%lux%lu", 
                desktop_geometry[0], desktop_geometry[1]);
            }
        }
        else {
            /* seperate values for desktops of different size */
            p_verbose("WM provides separate _NET_DESKTOP_GEOMETRY value for each desktop.\n");
            for (i = 0; i < *num_desktops; i++) {
                if (i < desktop_geometry_size / sizeof(*desktop_geometry) / 2) {
                    desktop_geometry_str[i] = g_strdup_printf("%lux%lu", 
                        desktop_geometry[i*2], desktop_geometry[i*2+1]);
                }
                else {
                    desktop_geometry_str[i] = g_strdup("N/A");
                }
            }
        }
    }
    else {
        for (i = 0; i < *num_desktops; i++) {
            desktop_geometry_str[i] = g_strdup("N/A");
        }
    }
 
    /* prepare desktop viewport strings */
    desktop_viewport_str = g_malloc0((*num_desktops + 1) * sizeof(char *));
    if (desktop_viewport && desktop_viewport_size > 0) {
        if (desktop_viewport_size == 2 * sizeof(*desktop_viewport)) {
            /* only one value - use it for current desktop */
            p_verbose("WM provides _NET_DESKTOP_VIEWPORT value only for the current desktop.\n");
            for (i = 0; i < *num_desktops; i++) {
                if (i == *cur_desktop) {
                    desktop_viewport_str[i] = g_strdup_printf("%lu,%lu", 
                        desktop_viewport[0], desktop_viewport[1]);
                }
                else {
                    desktop_viewport_str[i] = g_strdup("N/A");
                }
            }
        }
        else {
            /* seperate values for each of desktops */
            for (i = 0; i < *num_desktops; i++) {
                if (i < desktop_viewport_size / sizeof(*desktop_viewport) / 2) {
                    desktop_viewport_str[i] = g_strdup_printf("%lu,%lu", 
                        desktop_viewport[i*2], desktop_viewport[i*2+1]);
                }
                else {
                    desktop_viewport_str[i] = g_strdup("N/A");
                }
            }
        }
    }
    else {
        for (i = 0; i < *num_desktops; i++) {
            desktop_viewport_str[i] = g_strdup("N/A");
        }
    }
 
    /* prepare desktop workarea strings */
    desktop_workarea_str = g_malloc0((*num_desktops + 1) * sizeof(char *));
    if (desktop_workarea && desktop_workarea_size > 0) {
        if (desktop_workarea_size == 4 * sizeof(*desktop_workarea)) {
            /* only one value - use it for current desktop */
            p_verbose("WM provides _NET_WORKAREA value only for the current desktop.\n");
            for (i = 0; i < *num_desktops; i++) {
                if (i == *cur_desktop) {
                    desktop_workarea_str[i] = g_strdup_printf("%lu,%lu %lux%lu", 
                        desktop_workarea[0], desktop_workarea[1],
                        desktop_workarea[2], desktop_workarea[3]);
                }
                else {
                    desktop_workarea_str[i] = g_strdup("N/A");
                }
            }
        }
        else {
            /* seperate values for each of desktops */
            for (i = 0; i < *num_desktops; i++) {
                if (i < desktop_workarea_size / sizeof(*desktop_workarea) / 4) {
                    desktop_workarea_str[i] = g_strdup_printf("%lu,%lu %lux%lu", 
                        desktop_workarea[i*4], desktop_workarea[i*4+1],
                        desktop_workarea[i*4+2], desktop_workarea[i*4+3]);
                }
                else {
                    desktop_workarea_str[i] = g_strdup("N/A");
                }
            }
        }
    }
    else {
        for (i = 0; i < *num_desktops; i++) {
            desktop_workarea_str[i] = g_strdup("N/A");
        }
    }
 
    /* print the list */
    for (i = 0; i < *num_desktops; i++) {
        gchar *out = get_output_str(names[i], names_are_utf8);
        printf("%-2d %c DG: %-*s  VP: %-*s  WA: %-*s  %s\n", i, i == *cur_desktop ? '*' : '-',
                longest_str(desktop_geometry_str), desktop_geometry_str[i], 
                longest_str(desktop_viewport_str), desktop_viewport_str[i], 
                longest_str(desktop_workarea_str), desktop_workarea_str[i], 
                out ? out : "N/A");
        g_free(out);
    }
    
    p_verbose("Total number of desktops: %lu\n", *num_desktops);
    p_verbose("Current desktop ID (counted from zero): %lu\n", *cur_desktop);
    
    ret = EXIT_SUCCESS;
    goto cleanup;
    
cleanup:
    g_free(names);
    g_free(num_desktops);
    g_free(cur_desktop);
    g_free(desktop_geometry);
    g_strfreev(desktop_geometry_str);
    g_free(desktop_viewport);
    g_strfreev(desktop_viewport_str);
    g_free(desktop_workarea);
    g_strfreev(desktop_workarea_str);
    g_free(list);
    
    return ret;
}/*}}}*/
Exemplo n.º 10
0
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);
}
Exemplo n.º 11
0
Window* get_window_by_title(Display *disp, gchar *title, int *num)
{
    Window *client_list;
    unsigned long client_list_size;
	/*窗口总数*/
	int countAll = 0;
	/*具有相同标题title的窗口数目*/
	int count = 0;
	/*记录具有相同标题的窗口在client_list中的下标*/
	int *record;
	/*具有title标题的窗口*/
	Window *windows;
	int i = 0;


	setlocale(LC_ALL, "");
	init_charset();
    if((client_list = get_client_list(disp, &client_list_size)) == NULL)
	{
        return NULL; 
    } 

	countAll = client_list_size / sizeof(Window);
	record = (int*)malloc(sizeof(int) * countAll);

	for(i = 0; i < countAll; ++i)
	{
		record[i] = -1;
	}


	for(i = 0; i < countAll; ++i)
	{
		gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
#if MY_DEBUG_OUTPUT == 1
		g_print("after get_window_title**\n");
#endif
		gchar *title_out = get_output_str(title_utf8, TRUE);
#if MY_DEBUG_OUTPUT == 1
		g_print(title_out);
		g_print("*******title_out is ok??\n");
#endif
		if(g_strcasecmp(title, title_out) == 0)
		{
			record[i] = 1;
			++count;
		}
		g_free(title_utf8);
		g_free(title_out);
	}

	/*存放相同标题的窗口*/
	windows = (Window*)malloc(sizeof(Window)*count);
	for(i = 0; i < countAll; ++i)
	{
		if(record[i] > 0)
		{
			windows[i] = client_list[i];
		}
	}
	*num = count;

	free(record);
	return windows;
}