Can now force the desktop icons on a specific monitor
This commit is contained in:
parent
057438f706
commit
edfcc36614
140
src/desktop.c
140
src/desktop.c
|
@ -63,18 +63,16 @@ typedef struct _DesktopCategory DesktopCategory;
|
||||||
|
|
||||||
struct _Desktop
|
struct _Desktop
|
||||||
{
|
{
|
||||||
|
DesktopPrefs prefs;
|
||||||
|
|
||||||
/* workarea */
|
/* workarea */
|
||||||
gint x;
|
GdkRectangle window;
|
||||||
gint y;
|
GdkRectangle workarea;
|
||||||
gint width;
|
|
||||||
gint height;
|
|
||||||
|
|
||||||
/* icons */
|
/* icons */
|
||||||
DesktopIcon ** icon;
|
DesktopIcon ** icon;
|
||||||
size_t icon_cnt;
|
size_t icon_cnt;
|
||||||
|
|
||||||
/* layout */
|
|
||||||
DesktopLayout layout;
|
|
||||||
/* common */
|
/* common */
|
||||||
char * path;
|
char * path;
|
||||||
size_t path_cnt;
|
size_t path_cnt;
|
||||||
|
@ -154,13 +152,15 @@ Desktop * desktop_new(DesktopPrefs * prefs)
|
||||||
{
|
{
|
||||||
Desktop * desktop;
|
Desktop * desktop;
|
||||||
GdkScreen * screen;
|
GdkScreen * screen;
|
||||||
gint x;
|
|
||||||
gint y;
|
|
||||||
gint depth;
|
gint depth;
|
||||||
|
|
||||||
if((desktop = malloc(sizeof(*desktop))) == NULL)
|
if((desktop = object_new(sizeof(*desktop))) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
memset(desktop, 0, sizeof(*desktop));
|
memset(desktop, 0, sizeof(*desktop));
|
||||||
|
desktop->prefs.layout = DESKTOP_LAYOUT_FILES;
|
||||||
|
desktop->prefs.monitor = -1;
|
||||||
|
if(prefs != NULL)
|
||||||
|
memcpy(&desktop->prefs, prefs, sizeof(*prefs));
|
||||||
/* workarea */
|
/* workarea */
|
||||||
screen = gdk_screen_get_default();
|
screen = gdk_screen_get_default();
|
||||||
desktop->display = gdk_screen_get_display(screen);
|
desktop->display = gdk_screen_get_display(screen);
|
||||||
|
@ -171,10 +171,11 @@ Desktop * desktop_new(DesktopPrefs * prefs)
|
||||||
if((desktop->home = getenv("HOME")) == NULL
|
if((desktop->home = getenv("HOME")) == NULL
|
||||||
&& (desktop->home = g_get_home_dir()) == NULL)
|
&& (desktop->home = g_get_home_dir()) == NULL)
|
||||||
desktop->home = "/";
|
desktop->home = "/";
|
||||||
desktop_set_layout(desktop, (prefs != NULL) ? prefs->layout : DL_FILES);
|
desktop_set_layout(desktop, desktop->prefs.layout);
|
||||||
/* manage root window events */
|
/* manage root window events */
|
||||||
gdk_window_get_geometry(desktop->root, &x, &y, &desktop->width,
|
gdk_window_get_geometry(desktop->root, &desktop->window.x,
|
||||||
&desktop->height, &depth);
|
&desktop->window.y, &desktop->window.width,
|
||||||
|
&desktop->window.height, &depth);
|
||||||
gdk_window_set_events(desktop->root, gdk_window_get_events(
|
gdk_window_set_events(desktop->root, gdk_window_get_events(
|
||||||
desktop->root) | GDK_BUTTON_PRESS_MASK);
|
desktop->root) | GDK_BUTTON_PRESS_MASK);
|
||||||
gdk_window_add_filter(desktop->root, _new_on_root_event, desktop);
|
gdk_window_add_filter(desktop->root, _new_on_root_event, desktop);
|
||||||
|
@ -205,7 +206,8 @@ static gboolean _new_idle(gpointer data)
|
||||||
#endif
|
#endif
|
||||||
g_free(desktop->background);
|
g_free(desktop->background);
|
||||||
desktop->background = gdk_pixbuf_new_from_file_at_scale(p,
|
desktop->background = gdk_pixbuf_new_from_file_at_scale(p,
|
||||||
desktop->width, desktop->height, FALSE, &error);
|
desktop->window.width, desktop->window.height, FALSE,
|
||||||
|
&error);
|
||||||
config_delete(config);
|
config_delete(config);
|
||||||
if(desktop->background == NULL)
|
if(desktop->background == NULL)
|
||||||
{
|
{
|
||||||
|
@ -331,11 +333,14 @@ static GdkFilterReturn _event_expose(XExposeEvent * xevent, Desktop * desktop)
|
||||||
static GdkFilterReturn _event_configure(XConfigureEvent * xevent,
|
static GdkFilterReturn _event_configure(XConfigureEvent * xevent,
|
||||||
Desktop * desktop)
|
Desktop * desktop)
|
||||||
{
|
{
|
||||||
desktop->width = xevent->width;
|
desktop->window.x = xevent->x;
|
||||||
desktop->height = xevent->height;
|
desktop->window.y = xevent->y;
|
||||||
|
desktop->window.width = xevent->width;
|
||||||
|
desktop->window.height = xevent->height;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s() %dx%d\n", __func__, desktop->width,
|
fprintf(stderr, "DEBUG: %s() (%dx%d) @ (%d,%d))\n", __func__,
|
||||||
desktop->height);
|
desktop->window.width, desktop->window.height,
|
||||||
|
desktop->window.x, desktop->window.y);
|
||||||
#endif
|
#endif
|
||||||
g_idle_add(_new_idle, desktop); /* FIXME run it directly? */
|
g_idle_add(_new_idle, desktop); /* FIXME run it directly? */
|
||||||
return GDK_FILTER_CONTINUE;
|
return GDK_FILTER_CONTINUE;
|
||||||
|
@ -568,7 +573,7 @@ void desktop_delete(Desktop * desktop)
|
||||||
if(desktop->mime != NULL)
|
if(desktop->mime != NULL)
|
||||||
mime_delete(desktop->mime);
|
mime_delete(desktop->mime);
|
||||||
free(desktop->path);
|
free(desktop->path);
|
||||||
free(desktop);
|
object_delete(desktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -646,19 +651,19 @@ static void _layout_set_homescreen(Desktop * desktop, gpointer data);
|
||||||
void desktop_set_layout(Desktop * desktop, DesktopLayout layout)
|
void desktop_set_layout(Desktop * desktop, DesktopLayout layout)
|
||||||
{
|
{
|
||||||
_layout_delete(desktop);
|
_layout_delete(desktop);
|
||||||
desktop->layout = layout;
|
desktop->prefs.layout = layout;
|
||||||
switch(desktop->layout)
|
switch(layout)
|
||||||
{
|
{
|
||||||
case DL_APPLICATIONS:
|
case DESKTOP_LAYOUT_APPLICATIONS:
|
||||||
_layout_applications(desktop);
|
_layout_applications(desktop);
|
||||||
break;
|
break;
|
||||||
case DL_CATEGORIES:
|
case DESKTOP_LAYOUT_CATEGORIES:
|
||||||
_layout_categories(desktop);
|
_layout_categories(desktop);
|
||||||
break;
|
break;
|
||||||
case DL_FILES:
|
case DESKTOP_LAYOUT_FILES:
|
||||||
_layout_files(desktop);
|
_layout_files(desktop);
|
||||||
break;
|
break;
|
||||||
case DL_HOMESCREEN:
|
case DESKTOP_LAYOUT_HOMESCREEN:
|
||||||
_layout_homescreen(desktop);
|
_layout_homescreen(desktop);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -814,7 +819,7 @@ static void _layout_set_categories(Desktop * desktop, gpointer data)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
||||||
#endif
|
#endif
|
||||||
desktop_set_layout(desktop, DL_CATEGORIES);
|
desktop_set_layout(desktop, DESKTOP_LAYOUT_CATEGORIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _layout_set_homescreen(Desktop * desktop, gpointer data)
|
static void _layout_set_homescreen(Desktop * desktop, gpointer data)
|
||||||
|
@ -822,7 +827,7 @@ static void _layout_set_homescreen(Desktop * desktop, gpointer data)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
||||||
#endif
|
#endif
|
||||||
desktop_set_layout(desktop, DL_HOMESCREEN);
|
desktop_set_layout(desktop, DESKTOP_LAYOUT_HOMESCREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -833,13 +838,6 @@ int desktop_error(Desktop * desktop, char const * message, int ret)
|
||||||
return _desktop_error(desktop, message, strerror(errno), ret);
|
return _desktop_error(desktop, message, strerror(errno), ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _error_text(char const * message, int ret)
|
|
||||||
{
|
|
||||||
fputs("desktop: ", stderr);
|
|
||||||
perror(message);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* desktop_refresh */
|
/* desktop_refresh */
|
||||||
static void _refresh_current(Desktop * desktop);
|
static void _refresh_current(Desktop * desktop);
|
||||||
|
@ -911,15 +909,15 @@ static void _refresh_current(Desktop * desktop)
|
||||||
|
|
||||||
static int _current_loop(Desktop * desktop)
|
static int _current_loop(Desktop * desktop)
|
||||||
{
|
{
|
||||||
switch(desktop->layout)
|
switch(desktop->prefs.layout)
|
||||||
{
|
{
|
||||||
case DL_APPLICATIONS:
|
case DESKTOP_LAYOUT_APPLICATIONS:
|
||||||
return _current_loop_applications(desktop);
|
return _current_loop_applications(desktop);
|
||||||
case DL_CATEGORIES:
|
case DESKTOP_LAYOUT_CATEGORIES:
|
||||||
return _current_loop_categories(desktop);
|
return _current_loop_categories(desktop);
|
||||||
case DL_FILES:
|
case DESKTOP_LAYOUT_FILES:
|
||||||
return _current_loop_files(desktop);
|
return _current_loop_files(desktop);
|
||||||
case DL_HOMESCREEN:
|
case DESKTOP_LAYOUT_HOMESCREEN:
|
||||||
break; /* nothing to do */
|
break; /* nothing to do */
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1119,9 +1117,9 @@ static gboolean _current_done(Desktop * desktop)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
switch(desktop->layout)
|
switch(desktop->prefs.layout)
|
||||||
{
|
{
|
||||||
case DL_CATEGORIES:
|
case DESKTOP_LAYOUT_CATEGORIES:
|
||||||
_done_categories(desktop);
|
_done_categories(desktop);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1188,7 +1186,7 @@ static void _done_categories_open(Desktop * desktop, gpointer data)
|
||||||
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, dc->name);
|
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, dc->name);
|
||||||
#endif
|
#endif
|
||||||
desktop->category = dc;
|
desktop->category = dc;
|
||||||
desktop_set_layout(desktop, DL_APPLICATIONS);
|
desktop_set_layout(desktop, DESKTOP_LAYOUT_APPLICATIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean _done_timeout(gpointer data)
|
static gboolean _done_timeout(gpointer data)
|
||||||
|
@ -1254,16 +1252,16 @@ static int _align_compare(const void * a, const void * b);
|
||||||
void desktop_icons_align(Desktop * desktop)
|
void desktop_icons_align(Desktop * desktop)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int x = desktop->x;
|
int x = desktop->workarea.x;
|
||||||
int y = desktop->y;
|
int y = desktop->workarea.y;
|
||||||
|
|
||||||
qsort(desktop->icon, desktop->icon_cnt, sizeof(void*), _align_compare);
|
qsort(desktop->icon, desktop->icon_cnt, sizeof(void*), _align_compare);
|
||||||
for(i = 0; i < desktop->icon_cnt; i++)
|
for(i = 0; i < desktop->icon_cnt; i++)
|
||||||
{
|
{
|
||||||
if(y + DESKTOPICON_MAX_HEIGHT > desktop->height)
|
if(y + DESKTOPICON_MAX_HEIGHT > desktop->workarea.height)
|
||||||
{
|
{
|
||||||
x += DESKTOPICON_MAX_WIDTH;
|
x += DESKTOPICON_MAX_WIDTH;
|
||||||
y = desktop->y;
|
y = desktop->window.y;
|
||||||
}
|
}
|
||||||
desktopicon_move(desktop->icon[i], x, y);
|
desktopicon_move(desktop->icon[i], x, y);
|
||||||
y += DESKTOPICON_MAX_HEIGHT;
|
y += DESKTOPICON_MAX_HEIGHT;
|
||||||
|
@ -1377,6 +1375,13 @@ static int _desktop_error(Desktop * desktop, char const * message,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _error_text(char const * message, int ret)
|
||||||
|
{
|
||||||
|
fputs("desktop: ", stderr);
|
||||||
|
perror(message);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* desktop_serror */
|
/* desktop_serror */
|
||||||
static int _desktop_serror(Desktop * desktop, char const * message, int ret)
|
static int _desktop_serror(Desktop * desktop, char const * message, int ret)
|
||||||
|
@ -1400,7 +1405,7 @@ static Config * _desktop_get_config(Desktop * desktop)
|
||||||
config_delete(config);
|
config_delete(config);
|
||||||
if(pathname != NULL)
|
if(pathname != NULL)
|
||||||
object_delete(pathname);
|
object_delete(pathname);
|
||||||
_desktop_serror(NULL, "Could not load preferences", FALSE);
|
_desktop_serror(NULL, _("Could not load preferences"), FALSE);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
|
@ -1410,6 +1415,7 @@ static Config * _desktop_get_config(Desktop * desktop)
|
||||||
/* desktop_get_workarea */
|
/* desktop_get_workarea */
|
||||||
static int _desktop_get_workarea(Desktop * desktop)
|
static int _desktop_get_workarea(Desktop * desktop)
|
||||||
{
|
{
|
||||||
|
GdkScreen * screen;
|
||||||
Atom atom;
|
Atom atom;
|
||||||
Atom type;
|
Atom type;
|
||||||
int format;
|
int format;
|
||||||
|
@ -1418,6 +1424,14 @@ static int _desktop_get_workarea(Desktop * desktop)
|
||||||
unsigned char * p;
|
unsigned char * p;
|
||||||
unsigned long * u;
|
unsigned long * u;
|
||||||
|
|
||||||
|
screen = gdk_screen_get_default();
|
||||||
|
if(desktop->prefs.monitor >= 0 && desktop->prefs.monitor
|
||||||
|
< gdk_screen_get_n_monitors(screen))
|
||||||
|
{
|
||||||
|
gdk_screen_get_monitor_geometry(screen, desktop->prefs.monitor,
|
||||||
|
&desktop->workarea);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
atom = gdk_x11_get_xatom_by_name("_NET_WORKAREA");
|
atom = gdk_x11_get_xatom_by_name("_NET_WORKAREA");
|
||||||
if(XGetWindowProperty(GDK_DISPLAY_XDISPLAY(desktop->display),
|
if(XGetWindowProperty(GDK_DISPLAY_XDISPLAY(desktop->display),
|
||||||
GDK_WINDOW_XWINDOW(desktop->root), atom, 0,
|
GDK_WINDOW_XWINDOW(desktop->root), atom, 0,
|
||||||
|
@ -1427,14 +1441,15 @@ static int _desktop_get_workarea(Desktop * desktop)
|
||||||
if(cnt >= 4)
|
if(cnt >= 4)
|
||||||
{
|
{
|
||||||
u = (unsigned long *)p;
|
u = (unsigned long *)p;
|
||||||
desktop->x = u[0];
|
desktop->workarea.x = u[0];
|
||||||
desktop->y = u[1];
|
desktop->workarea.y = u[1];
|
||||||
desktop->width = u[2];
|
desktop->workarea.width = u[2];
|
||||||
desktop->height = u[3];
|
desktop->workarea.height = u[3];
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s() (%d, %d) %dx%d\n", __func__,
|
fprintf(stderr, "DEBUG: %s() (%d, %d) %dx%d\n", __func__,
|
||||||
desktop->x, desktop->y, desktop->width,
|
desktop->workarea.x, desktop->workarea.y,
|
||||||
desktop->height);
|
desktop->workarea.width,
|
||||||
|
desktop->workarea.height);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
XFree(p);
|
XFree(p);
|
||||||
|
@ -1445,13 +1460,14 @@ static int _desktop_get_workarea(Desktop * desktop)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fputs(_("Usage: desktop [-H | -V][-a | -c | -f | -h]\n"
|
fputs(_("Usage: desktop [-H|-V][-a|-c|-f|-h][-m monitor]\n"
|
||||||
" -H Place icons horizontally\n"
|
" -H Place icons horizontally\n"
|
||||||
" -V Place icons vertically\n"
|
" -V Place icons vertically\n"
|
||||||
" -a Display the applications registered\n"
|
" -a Display the applications registered\n"
|
||||||
" -c Sort the applications registered by category\n"
|
" -c Sort the applications registered by category\n"
|
||||||
" -f Display contents of the desktop folder (default)\n"
|
" -f Display contents of the desktop folder (default)\n"
|
||||||
" -h Display the homescreen\n"), stderr);
|
" -h Display the homescreen\n"
|
||||||
|
" -m Monitor where to display the desktop\n"), stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1470,9 +1486,10 @@ int main(int argc, char * argv[])
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
textdomain(PACKAGE);
|
textdomain(PACKAGE);
|
||||||
memset(&prefs, 0, sizeof(prefs));
|
memset(&prefs, 0, sizeof(prefs));
|
||||||
prefs.layout = DL_FILES;
|
prefs.layout = DESKTOP_LAYOUT_FILES;
|
||||||
|
prefs.monitor = -1;
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
while((o = getopt(argc, argv, "HVacfh")) != -1)
|
while((o = getopt(argc, argv, "HVacfhm:")) != -1)
|
||||||
switch(o)
|
switch(o)
|
||||||
{
|
{
|
||||||
case 'H':
|
case 'H':
|
||||||
|
@ -1480,16 +1497,19 @@ int main(int argc, char * argv[])
|
||||||
/* FIXME implement */
|
/* FIXME implement */
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
prefs.layout = DL_APPLICATIONS;
|
prefs.layout = DESKTOP_LAYOUT_APPLICATIONS;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
prefs.layout = DL_CATEGORIES;
|
prefs.layout = DESKTOP_LAYOUT_CATEGORIES;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
prefs.layout = DL_FILES;
|
prefs.layout = DESKTOP_LAYOUT_FILES;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
prefs.layout = DL_HOMESCREEN;
|
prefs.layout = DESKTOP_LAYOUT_HOMESCREEN;
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
prefs.monitor = strtol(optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return _usage();
|
return _usage();
|
||||||
|
|
|
@ -35,7 +35,8 @@ typedef struct _Desktop Desktop;
|
||||||
# endif
|
# endif
|
||||||
typedef enum _DesktopLayout
|
typedef enum _DesktopLayout
|
||||||
{
|
{
|
||||||
DL_APPLICATIONS, DL_CATEGORIES, DL_FILES, DL_HOMESCREEN
|
DESKTOP_LAYOUT_APPLICATIONS, DESKTOP_LAYOUT_CATEGORIES,
|
||||||
|
DESKTOP_LAYOUT_FILES, DESKTOP_LAYOUT_HOMESCREEN
|
||||||
} DesktopLayout;
|
} DesktopLayout;
|
||||||
|
|
||||||
typedef struct _DesktopPrefs
|
typedef struct _DesktopPrefs
|
||||||
|
|
Loading…
Reference in New Issue
Block a user