summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquinn <quinn>2007-01-28 01:30:12 +0000
committerquinn <quinn>2007-01-28 01:30:12 +0000
commitaec2bdfcab3d2b1f90a6e8a873a120836efa2988 (patch)
treec65e0418835d7dc5e9796bd9e2a9f9c34dd10855
parent15b316b938956ad1f4c0d0f643acb1703a9c2c34 (diff)
downloadberyl-desktop-manager-aec2bdfcab3d2b1f90a6e8a873a120836efa2988.tar.gz
beryl-desktop-manager-aec2bdfcab3d2b1f90a6e8a873a120836efa2988.tar.bz2
beryl-desktop-manager:
* massive rearchitecturing :-P
-rw-r--r--src/bdm.c172
1 files changed, 114 insertions, 58 deletions
diff --git a/src/bdm.c b/src/bdm.c
index 53adecf..1b1b3f9 100644
--- a/src/bdm.c
+++ b/src/bdm.c
@@ -17,37 +17,82 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
-cairo_t * g_pCairoContext;
+//quinn was here
+#define NEW(a,b) a * b ;\
+ b = malloc(sizeof(a));\
+ memset((b),0,sizeof(a));
-static void render (int width, int height, GdkPixbuf *pixbuf)
+typedef enum
{
- cairo_set_source_rgba(g_pCairoContext,0,0,0,0);
- cairo_paint(g_pCairoContext);
- cairo_save(g_pCairoContext);
- gdk_cairo_set_source_pixbuf(g_pCairoContext,pixbuf,0,0);
- cairo_rectangle(g_pCairoContext, 0, 0, width,height);
- cairo_fill(g_pCairoContext);
- cairo_stroke(g_pCairoContext);
+ WALLPAPER_TYPE_PIXBUF,
+ WALLPAPER_TYPE_COUNT
+} WallpaperType;
+
+typedef struct _PixbufWallpaper
+{
+ GdkPixbuf * source;
+ int width;
+ int height;
+} PixbufWallpaper;
+
+typedef union _WallUnion
+{
+ PixbufWallpaper pixbuf;
+} WallUnion;
+
+typedef struct _Wallpaper
+{
+ WallpaperType type;
+ WallUnion data;
+} Wallpaper;
+
+typedef struct _ScreenArea
+{
+ int width;
+ int height;
+ Wallpaper * wallpaper;
+ GtkWidget * window;
+} ScreenArea;
+
+GSList * Wallpapers=NULL;
+
+static void render_pixbuf (cairo_t * cr, ScreenArea * area)
+{
+ cairo_set_source_rgba(cr,0,0,0,0);
+ cairo_paint(cr);
+ cairo_save(cr);
+ cairo_scale(cr,((double)area->width/(double)area->wallpaper->data.pixbuf.width),
+ ((double)area->height/(double)area->wallpaper->data.pixbuf.height));
+ gdk_cairo_set_source_pixbuf(cr,area->wallpaper->data.pixbuf.source,0,0);
+ cairo_rectangle(cr, 0, 0, area->width,area->height);
+ cairo_fill(cr);
+ cairo_stroke(cr);
- cairo_paint(g_pCairoContext);
- cairo_restore(g_pCairoContext);
+ cairo_paint(cr);
+ cairo_restore(cr);
}
-static gboolean on_alpha_window_expose(GtkWidget * widget, GdkEventExpose * expose, GdkPixbuf *pixbuf)
+static void render (ScreenArea * area)
{
- int iWidth;
- int iHeight;
- g_pCairoContext = gdk_cairo_create(widget->window);
-
- cairo_set_operator (g_pCairoContext, CAIRO_OPERATOR_SOURCE);
- gtk_window_get_size(GTK_WINDOW(widget),&iWidth,&iHeight);
- render(iWidth,iHeight,pixbuf);
- cairo_destroy (g_pCairoContext);
-
+ cairo_t * cr;
+ cr = gdk_cairo_create(GTK_WIDGET(area->window)->window);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ switch(area->wallpaper->type)
+ {
+ case WALLPAPER_TYPE_PIXBUF:
+ render_pixbuf(cr,area);
+ break;
+ default:
+ break;
+ }
+ cairo_destroy (cr);
}
-
+static gboolean on_alpha_window_expose(GtkWidget * widget, GdkEventExpose * expose, ScreenArea * area)
+{
+ render(area);
+}
static void on_alpha_screen_changed(GtkWidget * widget, GdkScreen * pOldScreen, GtkWidget * label)
{
@@ -75,7 +120,7 @@ int main(int argc, char * argv[])
int numx, numy;
int i;
int j;
- Bool backwards;
+ int k;
display = XOpenDisplay(getenv("DISPLAY"));
root = XDefaultRootWindow(display);
@@ -137,56 +182,67 @@ int main(int argc, char * argv[])
return 1;
}
- gchar * wallpapers[numy][numx];
- for (j = 0; j < numy; j++)
+ for(i = 0; i < n_keys; i++)
{
- for (i = 0; i < numx; i++)
+ //for now just assume all are pixbuf
+ gchar * s = g_key_file_get_string(kf,"wallpapers",keys[i],NULL);
+ NEW(Wallpaper,w);
+ w->type=WALLPAPER_TYPE_PIXBUF;
+ w->data.pixbuf.source=gdk_pixbuf_new_from_file(s,NULL);
+ if (w->data.pixbuf.source)
{
- wallpapers[j][i] = g_key_file_get_string (kf, "wallpapers",
- keys[(j*numx+i) % n_keys],
- NULL);
- fprintf(stderr,"%s\n",wallpapers[j][i]);
+ w->data.pixbuf.width=gdk_pixbuf_get_width(w->data.pixbuf.source);
+ w->data.pixbuf.height=gdk_pixbuf_get_height(w->data.pixbuf.source);
+ Wallpapers=g_slist_append(Wallpapers,w);
}
+ else
+ {
+ free(w);
+ }
+ }
+ if (!Wallpapers)
+ {
+ fprintf (stderr, "All your wallpapers are belong to NULL.\n");
+ return 1;
}
g_key_file_free (kf);
- backwards = FALSE;
+ GSList * wp = Wallpapers;
for (j = 0; j < numy; j++)
{
-
for (i = 0; i < numx; i++)
{
- GtkWidget * dwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_default_size(GTK_WINDOW(dwindow),onex,oney);
- gtk_window_set_screen(GTK_WINDOW(dwindow),gdk_screen_get_default());
- gtk_window_set_decorated(GTK_WINDOW(dwindow),FALSE);
- gtk_window_set_type_hint(GTK_WINDOW(dwindow),GDK_WINDOW_TYPE_HINT_DESKTOP);
- GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(wallpapers[j][i],NULL);
- GdkPixbuf * scaledpix = gdk_pixbuf_scale_simple(pixbuf,1280,800,GDK_INTERP_NEAREST);
- g_object_unref (G_OBJECT (pixbuf));
- //GtkImage * image = gtk_image_new_from_pixbuf(scaledpix);
- //gtk_widget_show(image);
- //gtk_container_add(GTK_CONTAINER(dwindow),GTK_WIDGET(image));
- gtk_window_move(GTK_WINDOW(dwindow),i*onex,j*oney);
- on_alpha_screen_changed(dwindow,NULL,NULL);
- gtk_window_resize(GTK_WINDOW(dwindow),onex,oney);
- gtk_widget_set_app_paintable(dwindow, TRUE);
- gtk_window_set_keep_below(GTK_WINDOW(dwindow),TRUE);
- g_signal_connect( G_OBJECT(dwindow),"expose-event",G_CALLBACK(on_alpha_window_expose),scaledpix);
- gtk_widget_show(dwindow);
- on_alpha_window_expose(dwindow,0,scaledpix);
+ for (k = 0; k < gdk_screen_get_n_monitors(gdk_screen_get_default()); k++)
+ {
+ GdkRectangle R;
+ NEW(ScreenArea,sa);
+ gdk_screen_get_monitor_geometry(gdk_screen_get_default(),k,&R);
+ sa->width=R.width;
+ sa->height=R.height;
+ GtkWidget * dwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ sa->window=dwindow;
+ sa->wallpaper=wp->data;
+ wp=wp->next;
+ if (!wp) wp=Wallpapers;
+ gtk_window_set_default_size(GTK_WINDOW(dwindow),onex,oney);
+ gtk_window_set_screen(GTK_WINDOW(dwindow),gdk_screen_get_default());
+ gtk_window_set_decorated(GTK_WINDOW(dwindow),FALSE);
+ gtk_window_set_type_hint(GTK_WINDOW(dwindow),GDK_WINDOW_TYPE_HINT_DESKTOP);
+ gtk_window_move(GTK_WINDOW(dwindow),i*onex+R.x,j*oney+R.y);
+ on_alpha_screen_changed(dwindow,NULL,NULL);
+ gtk_window_resize(GTK_WINDOW(dwindow),R.width,R.height);
+ gtk_widget_set_app_paintable(dwindow, TRUE);
+ gtk_window_set_keep_below(GTK_WINDOW(dwindow),TRUE);
+ g_signal_connect( G_OBJECT(dwindow),"expose-event",G_CALLBACK(on_alpha_window_expose),sa);
+ gtk_widget_show(dwindow);
+ on_alpha_window_expose(dwindow,0,sa);
+ }
}
}
gtk_main();
- for (j = 0; j < numy; j++)
- {
- for (i = 0; i < numx; i++)
- {
- g_free (wallpapers[j][i]);
- }
- }
+ //yes I know there is unfreed stuff, its intentional, the system can take care of it
}