new utility function

2002-06-22  Havoc Pennington  <hp@pobox.com>

	* src/xprops.c (meta_prop_get_utf8_list): new utility function

	* src/display.c (meta_display_open): _NET_DESKTOP_NAMES atom
	(event_callback): update workspace names when the property changes

	* src/screen.c (set_supported_hint): "support" _NET_DESKTOP_NAMES
	(nothing to do really)
This commit is contained in:
Havoc Pennington 2002-06-22 04:52:35 +00:00 committed by Havoc Pennington
parent de42a62f4e
commit 0243071f15
9 changed files with 186 additions and 1 deletions

View File

@ -1,3 +1,13 @@
2002-06-22 Havoc Pennington <hp@pobox.com>
* src/xprops.c (meta_prop_get_utf8_list): new utility function
* src/display.c (meta_display_open): _NET_DESKTOP_NAMES atom
(event_callback): update workspace names when the property changes
* src/screen.c (set_supported_hint): "support" _NET_DESKTOP_NAMES
(nothing to do really)
2002-06-21 Havoc Pennington <hp@pobox.com> 2002-06-21 Havoc Pennington <hp@pobox.com>
Theme breakage! Themes have to implement "border" frames Theme breakage! Themes have to implement "border" frames

View File

@ -355,6 +355,7 @@ meta_display_open (const char *name)
display->atom_timestamp = atoms[62]; display->atom_timestamp = atoms[62];
display->atom_version = atoms[63]; display->atom_version = atoms[63];
display->atom_atom_pair = atoms[64]; display->atom_atom_pair = atoms[64];
display->atom_net_desktop_names = atoms[65];
/* Offscreen unmapped window used for _NET_SUPPORTING_WM_CHECK, /* Offscreen unmapped window used for _NET_SUPPORTING_WM_CHECK,
* created in screen_new * created in screen_new
@ -1383,6 +1384,9 @@ event_callback (XEvent *event,
if (event->xproperty.atom == if (event->xproperty.atom ==
display->atom_net_desktop_layout) display->atom_net_desktop_layout)
meta_screen_update_workspace_layout (screen); meta_screen_update_workspace_layout (screen);
else if (event->xproperty.atom ==
display->atom_net_desktop_names)
meta_screen_update_workspace_names (screen);
} }
} }
break; break;

View File

@ -137,6 +137,7 @@ struct _MetaDisplay
Atom atom_timestamp; Atom atom_timestamp;
Atom atom_version; Atom atom_version;
Atom atom_atom_pair; Atom atom_atom_pair;
Atom atom_net_desktop_names;
/* This is the actual window from focus events, /* This is the actual window from focus events,
* not the one we last set * not the one we last set

View File

@ -81,7 +81,7 @@ set_wm_check_hint (MetaScreen *screen)
static int static int
set_supported_hint (MetaScreen *screen) set_supported_hint (MetaScreen *screen)
{ {
#define N_SUPPORTED 32 #define N_SUPPORTED 33
#define N_WIN_SUPPORTED 1 #define N_WIN_SUPPORTED 1
Atom atoms[N_SUPPORTED]; Atom atoms[N_SUPPORTED];
@ -117,6 +117,7 @@ set_supported_hint (MetaScreen *screen)
atoms[29] = screen->display->atom_net_wm_workarea; atoms[29] = screen->display->atom_net_wm_workarea;
atoms[30] = screen->display->atom_net_show_desktop; atoms[30] = screen->display->atom_net_show_desktop;
atoms[31] = screen->display->atom_net_desktop_layout; atoms[31] = screen->display->atom_net_desktop_layout;
atoms[32] = screen->display->atom_net_desktop_names;
XChangeProperty (screen->display->xdisplay, screen->xroot, XChangeProperty (screen->display->xdisplay, screen->xroot,
screen->display->atom_net_supported, screen->display->atom_net_supported,
@ -460,6 +461,7 @@ meta_screen_new (MetaDisplay *display,
set_wm_check_hint (screen); set_wm_check_hint (screen);
meta_screen_update_workspace_layout (screen); meta_screen_update_workspace_layout (screen);
meta_screen_update_workspace_names (screen);
/* Screens must have at least one workspace at all times, /* Screens must have at least one workspace at all times,
* so create that required workspace. * so create that required workspace.
@ -1112,6 +1114,45 @@ meta_screen_update_workspace_layout (MetaScreen *screen)
screen->vertical_workspaces); screen->vertical_workspaces);
} }
void
meta_screen_update_workspace_names (MetaScreen *screen)
{
char **names;
int n_names;
int i;
GList *tmp;
names = NULL;
n_names = 0;
if (!meta_prop_get_utf8_list (screen->display,
screen->xroot,
screen->display->atom_net_desktop_names,
&names, &n_names))
{
meta_verbose ("Failed to get workspace names from root window %d\n",
screen->number);
return;
}
i = 0;
tmp = screen->display->workspaces;
while (tmp != NULL && i < n_names)
{
MetaWorkspace *w = tmp->data;
if (w->screen == screen)
{
meta_workspace_set_name (w, names[i]);
++i;
}
tmp = tmp->next;
}
g_strfreev (names);
}
Window Window
meta_create_offscreen_window (Display *xdisplay, meta_create_offscreen_window (Display *xdisplay,
Window parent) Window parent)

View File

@ -106,6 +106,7 @@ const MetaXineramaScreenInfo* meta_screen_get_xinerama_for_window (MetaScreen *s
MetaWindow *window); MetaWindow *window);
void meta_screen_update_workspace_layout (MetaScreen *screen); void meta_screen_update_workspace_layout (MetaScreen *screen);
void meta_screen_update_workspace_names (MetaScreen *screen);
Window meta_create_offscreen_window (Display *xdisplay, Window meta_create_offscreen_window (Display *xdisplay,
Window parent); Window parent);

View File

@ -23,6 +23,7 @@
#include "workspace.h" #include "workspace.h"
#include "errors.h" #include "errors.h"
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <string.h>
void meta_workspace_queue_calc_showing (MetaWorkspace *workspace); void meta_workspace_queue_calc_showing (MetaWorkspace *workspace);
@ -48,6 +49,9 @@ meta_workspace_new (MetaScreen *screen)
workspace->work_area.height = screen->height; workspace->work_area.height = screen->height;
workspace->work_area_invalid = TRUE; workspace->work_area_invalid = TRUE;
workspace->name = g_strdup_printf (_("Workspace %d\n"),
meta_workspace_index (workspace) + 1);
/* Update hint for current number of workspaces */ /* Update hint for current number of workspaces */
set_number_of_spaces_hint (screen); set_number_of_spaces_hint (screen);
@ -87,10 +91,15 @@ meta_workspace_free (MetaWorkspace *workspace)
workspace->screen->display->workspaces = workspace->screen->display->workspaces =
g_list_remove (workspace->screen->display->workspaces, workspace); g_list_remove (workspace->screen->display->workspaces, workspace);
g_free (workspace->name);
g_free (workspace); g_free (workspace);
/* Update hint for current number of workspaces */ /* Update hint for current number of workspaces */
set_number_of_spaces_hint (screen); set_number_of_spaces_hint (screen);
/* don't bother to reset names, pagers can just ignore
* extra ones
*/
} }
void void
@ -747,3 +756,16 @@ meta_workspace_ensure_tab_popup (MetaDisplay *display,
/* don't show tab popup, since proper window isn't selected yet */ /* don't show tab popup, since proper window isn't selected yet */
} }
void
meta_workspace_set_name (MetaWorkspace *workspace,
const char *name)
{
if (strcmp (name, workspace->name) == 0)
return;
g_free (workspace->name);
workspace->name = g_strdup (name);
meta_verbose ("Workspace has new name \"%s\"\n",
workspace->name);
}

View File

@ -41,6 +41,8 @@ struct _MetaWorkspace
GList *windows; GList *windows;
char *name;
MetaRectangle work_area; MetaRectangle work_area;
guint work_area_invalid : 1; guint work_area_invalid : 1;
}; };
@ -72,6 +74,9 @@ MetaWorkspace* meta_workspace_get_neighbor (MetaWorkspace *workspace,
void meta_workspace_ensure_tab_popup (MetaDisplay *display, void meta_workspace_ensure_tab_popup (MetaDisplay *display,
MetaScreen *screen); MetaScreen *screen);
void meta_workspace_set_name (MetaWorkspace *workspace,
const char *name);
#endif #endif

View File

@ -24,6 +24,7 @@
#include "errors.h" #include "errors.h"
#include "util.h" #include "util.h"
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <string.h>
static gboolean static gboolean
check_type_and_format (MetaDisplay *display, check_type_and_format (MetaDisplay *display,
@ -291,6 +292,101 @@ meta_prop_get_utf8_string (MetaDisplay *display,
return TRUE; return TRUE;
} }
gboolean
meta_prop_get_utf8_list (MetaDisplay *display,
Window xwindow,
Atom xatom,
char ***str_p,
int *n_str_p)
{
Atom type;
int format;
gulong bytes_after;
guchar *val;
gulong n_items;
int i;
int n_strings;
char **retval;
const char *p;
*str_p = NULL;
*n_str_p = 0;
meta_error_trap_push (display);
if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
0, G_MAXLONG,
False, display->atom_utf8_string,
&type, &format, &n_items,
&bytes_after, (guchar **)&val) != Success ||
type == None)
{
meta_error_trap_pop (display);
return FALSE;
}
if (meta_error_trap_pop (display) != Success)
return FALSE;
if (!check_type_and_format (display, xwindow, xatom, 8,
display->atom_utf8_string,
-1, format, type))
{
XFree (val);
return FALSE;
}
/* I'm not sure this is right, but I'm guessing the
* property is nul-separated
*/
i = 0;
n_strings = 1;
while (i < (int) n_items)
{
if (val[i] == '\0')
++n_strings;
++i;
}
/* we're guaranteed that val has a nul on the end
* by XGetWindowProperty
*/
retval = g_new0 (char*, n_strings + 1);
p = val;
i = 0;
while (i < n_strings)
{
if (!g_utf8_validate (p, -1, NULL))
{
char *name;
meta_error_trap_push (display);
name = XGetAtomName (display->xdisplay, xatom);
meta_error_trap_pop (display);
meta_warning (_("Property %s on window 0x%lx contained invalid UTF-8 for item %d in the list\n"),
name, xwindow, i);
meta_XFree (name);
meta_XFree (val);
g_strfreev (retval);
return FALSE;
}
retval[i] = g_strdup (p);
p = p + strlen (p) + 1;
++i;
}
*str_p = retval;
*n_str_p = i;
meta_XFree (val);
return TRUE;
}
gboolean gboolean
meta_prop_get_window (MetaDisplay *display, meta_prop_get_window (MetaDisplay *display,
Window xwindow, Window xwindow,

View File

@ -89,6 +89,11 @@ gboolean meta_prop_get_utf8_string (MetaDisplay *display,
Window xwindow, Window xwindow,
Atom xatom, Atom xatom,
char **str_p); char **str_p);
gboolean meta_prop_get_utf8_list (MetaDisplay *display,
Window xwindow,
Atom xatom,
char ***str_p,
int *n_str_p);
gboolean meta_prop_get_window (MetaDisplay *display, gboolean meta_prop_get_window (MetaDisplay *display,
Window xwindow, Window xwindow,
Atom xatom, Atom xatom,