The panel can now be on different monitors

This commit is contained in:
Pierre Pronchery 2010-01-17 00:31:27 +00:00
parent 8bc220567c
commit 47b0da3278
3 changed files with 32 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Panel */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,6 +23,11 @@
/* types */
typedef struct _Panel Panel;
typedef struct _PanelPrefs
{
int monitor;
} PanelPrefs;
/* constants */
#define PANEL_BORDER_WIDTH 4
@ -30,7 +35,7 @@ typedef struct _Panel Panel;
/* functions */
Panel * panel_new(void);
Panel * panel_new(PanelPrefs * prefs);
void panel_delete(Panel * panel);
/* useful */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Panel */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,7 +17,9 @@
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <gtk/gtk.h>
#include "common.h"
@ -27,7 +29,7 @@
/* usage */
static int _usage(void)
{
fputs("Usage: " PACKAGE "\n", stderr);
fputs("Usage: " PACKAGE " [-m monitor]\n", stderr);
return 1;
}
@ -39,18 +41,26 @@ int main(int argc, char * argv[])
{
int o;
Panel * panel;
PanelPrefs prefs;
char * p;
struct sigaction sa;
gtk_init(&argc, &argv);
while((o = getopt(argc, argv, "")) != -1)
memset(&prefs, 0, sizeof(prefs));
while((o = getopt(argc, argv, "m:")) != -1)
switch(o)
{
case 'm':
prefs.monitor = strtol(optarg, &p, 10);
if(optarg[0] == '\0' || *p != '\0')
return _usage();
break;
default:
return _usage();
}
if(optind != argc)
return _usage();
if((panel = panel_new()) == NULL)
if((panel = panel_new(&prefs)) == NULL)
return 2;
sa.sa_handler = _main_sigchld;
sigemptyset(&sa.sa_mask);

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Panel */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -72,10 +72,11 @@ static gboolean _on_button_press(GtkWidget * widget, GdkEventButton * event,
gpointer data);
static gboolean _on_closex(void);
Panel * panel_new(void)
Panel * panel_new(PanelPrefs * prefs)
{
Panel * panel;
GdkScreen * screen;
int monitor;
GtkWidget * event;
GdkRectangle rect;
@ -102,7 +103,12 @@ Panel * panel_new(void)
/* root window */
panel->root = gdk_screen_get_root_window(gdk_screen_get_default());
screen = gdk_screen_get_default();
gdk_screen_get_monitor_geometry(screen, 0, &rect);
if(prefs != NULL && prefs->monitor > 0
&& prefs->monitor < gdk_screen_get_n_monitors(screen))
monitor = prefs->monitor;
else
monitor = 0;
gdk_screen_get_monitor_geometry(screen, monitor, &rect);
panel->root_width = rect.width;
panel->root_height = rect.height;
#ifdef DEBUG
@ -120,8 +126,8 @@ Panel * panel_new(void)
rect.height);
gtk_window_set_type_hint(GTK_WINDOW(panel->window),
GDK_WINDOW_TYPE_HINT_DOCK);
gtk_window_move(GTK_WINDOW(panel->window), 0, panel->root_height
- rect.height);
gtk_window_move(GTK_WINDOW(panel->window), rect.x,
rect.y + panel->root_height - rect.height);
gtk_window_stick(GTK_WINDOW(panel->window));
g_signal_connect(G_OBJECT(panel->window), "delete-event", G_CALLBACK(
_on_closex), panel);