|
Thanks for your comments they were quite helpful. PCMan wrote: I thought we might be able to integrate the customization into lxappearance. Which would solve the difficult configuration issues.It's already reviewed,but not yet applied because some modifications might be needed and the following issues need to be addressed. The approch used in the patch is originally planned by me, too, but:Pros: 1. Simple and easily maintained. 2. Don't need additional config files 3. Compatible with current fd.o specs Cons: 1. Not flexible and user customization can be difficult I have further implemented the code to include the gnome background style options: centered, fill, scaled, zoom, and tiled. I left tiled as the default. The attached file is an interim difference patch that includes these changes.2. Only a background image can be specified. Additional information, such as whether to stretch the image or not, cannot be stored unless you add some new keys to the directory file. This requires even more modifications to the menu-cache libs. This is a difficult decision to make. It is hard to code this to accept all other themes and not create your own. just taking a look at Gnome and KDE I see that they have a different theme structure. It will be hard to be generic to multiple desktop themes. Maybe we could use X-LXDE-Background for lxde specific keys. Unless you can see another way of using XDG's specification to get the background file from the .directory.3. This key-value is not useful to any other programs in LXDE. So, is it worthy enough to change menu-cache API globally just for this rarely used, lxlauncher-specific stuff? Get the path of the directory file with menu-cache API, and read the file for X-background value with GKeyFile in LXLauncher is more reasonable for API design, but it's less efficient. menu-cache should be a general purpose lib, not a lxde or lxlauncher specific one. You don't need to copy it. they could have their own local file, and if chosen as a background would be symlinked to .local/share/backgrounds, for example.4. If the user wants to change the image, he/she will need to copy the directory file to his/her own home dir, and edit it, which is quite complicated, requiring more disk space, and hard to maintain. So, I'll propose another approach described in my wiki post. In the long run, this can be more preferable to lxlauncher and the whole LXDE and also leave room for future user customization. Having a theme definition file can also make it easy for artists to make their lxlauncher themes. The drawing code in the patch can be applied to svn, but for X-Background stuff, there are issues I addressed in preceding lines. BTW, using cairo means we can fully-utilize vector-based drawing to paint the background. So that's why I want a more flexible theme definition file. Otherwise, if we only need to paint a image file to the background, smiple gdk + x11 without cairo can do it well and even better. Any opinions? On Wed, Apr 1, 2009 at 1:20 AM, Brent McCarthy <[email protected]> wrote: |
diff -u lxlauncher/src/lxlauncher.c lxlauncher/src/lxlauncher.c
--- lxlauncher/src/lxlauncher.c (working copy)
+++ lxlauncher/src/lxlauncher.c (working copy)
@@ -47,10 +47,47 @@
static gint image_size = IMG_SIZE;
static gchar* background_image = NULL;
+static gboolean no_background = FALSE;
+
+enum {
+ TILED_STYLE,
+ CENTERED_STYLE,
+ FILL_STYLE,
+ SCALED_STYLE,
+ ZOOM_STYLE,
+} background_style = TILED_STYLE;
+
+static gboolean
+background_style_option (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ if (! strcmp (value, "tiled"))
+ background_style = TILED_STYLE;
+ else if (! strcmp (value, "centered"))
+ background_style = CENTERED_STYLE;
+ else if (! strcmp (value, "fill"))
+ background_style = FILL_STYLE;
+ else if (! strcmp (value, "scaled"))
+ background_style = SCALED_STYLE;
+ else if (! strcmp (value, "zoom"))
+ background_style = ZOOM_STYLE;
+ else
+ {
+ g_set_error(error, NULL, NULL,
+ "unrecognized background style: %s", value);
+ return FALSE;
+ }
+ return TRUE;
+}
+
static GOptionEntry entries[] =
{
{"icon-size", 'i', 0, G_OPTION_ARG_INT, &image_size, "Button icon size NxN", "N"},
{"background-image", 'b', 0, G_OPTION_ARG_FILENAME, &background_image, "Background image", "FILENAME"},
+ {"style", 's', 0, G_OPTION_ARG_CALLBACK, background_style_option, "Background style (tiled|centered|fill|scaled|zoom)", "<style>"},
+ {"no-background", 'n', 0, G_OPTION_ARG_NONE, &no_background, "Do not show Background", NULL},
{NULL}
};
@@ -263,7 +300,7 @@
{
GObjectClass* oc = G_OBJECT_GET_CLASS(w);
GtkWidgetClass* wc = (GtkWidgetClass*)g_type_class_peek_parent( oc );
- GdkPixmap* pixmap = (GdkPixmap*)data;
+ GdkPixbuf* pixbuf = (GdkPixbuf*)data;
if( GTK_WIDGET_DRAWABLE(w) && evt->window == ((GtkViewport*)w)->bin_window )
{
@@ -273,30 +310,67 @@
GtkWidget* scroll = gtk_widget_get_parent(w);
GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(scroll);
- cr = gdk_cairo_create (evt->window);
- //pat = cairo_pattern_create_linear( 0, gtk_adjustment_get_value(vadj), 0, w->allocation.height + gtk_adjustment_get_value(vadj) );
- //cairo_pattern_add_color_stop_rgb( pat, 0, 1, 1, 1);
- //cairo_pattern_add_color_stop_rgb( pat, 1.0, ((gdouble)184/256), ((gdouble)215/256), ((gdouble)235/256));
-// cairo_rectangle(cr, 0, 0, w->allocation.width, w->allocation.height );
-// cairo_rectangle(cr, evt->area.x, evt->area.y, evt->area.width, evt->area.height );
- cairo_rectangle(cr, evt->area.x, evt->area.y, evt->area.width, evt->area.height );
- //cairo_set_source(cr, pat);
- //cairo_set_source_rgb(cr, 184.0/256, 215.0/256, 235.0/256);
- //cairo_fill(cr);
- //cairo_pattern_destroy(pat);
-
- if( pixmap )
- {
- gdk_cairo_set_source_pixmap(cr, pixmap, 0, 0);
- pat = cairo_get_source(cr);
- cairo_pattern_set_extend(pat, CAIRO_EXTEND_REPEAT);
- }
- else
+ if(!no_background)
{
- cairo_set_source_rgb(cr, 184.0/256, 215.0/256, 235.0/256);
+ cr = gdk_cairo_create (evt->window);
+ //pat = cairo_pattern_create_linear( 0, gtk_adjustment_get_value(vadj), 0, w->allocation.height + gtk_adjustment_get_value(vadj) );
+ //cairo_pattern_add_color_stop_rgb( pat, 0, 1, 1, 1);
+ //cairo_pattern_add_color_stop_rgb( pat, 1.0, ((gdouble)184/256), ((gdouble)215/256), ((gdouble)235/256));
+// cairo_rectangle(cr, 0, 0, w->allocation.width, w->allocation.height );
+// cairo_rectangle(cr, evt->area.x, evt->area.y, evt->area.width, evt->area.height );
+ cairo_rectangle(cr, evt->area.x, evt->area.y, evt->area.width, evt->area.height );
+ //cairo_set_source(cr, pat);
+ //cairo_pattern_destroy(pat);
+
+ if( pixbuf )
+ {
+ gint x,y,width,height,depth;
+ gdk_window_get_geometry(evt->window, &x, &y, &width, &height, &depth);
+ double p_width = gdk_pixbuf_get_width(pixbuf);
+ double p_height = gdk_pixbuf_get_height(pixbuf);
+ double scale_x = width/p_width;
+ double scale_y = height/p_height;
+ double scale = 1.0;
+
+ if( background_style == CENTERED_STYLE )
+ {
+ gdk_cairo_set_source_pixbuf(cr, pixbuf, (width - p_width*scale)/2, (height - p_height*scale)/2);
+ }
+ else if( background_style == FILL_STYLE )
+ {
+ GdkPixbuf* fill_pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
+ gdk_cairo_set_source_pixbuf(cr, fill_pixbuf, 0, 0);
+ g_object_unref( fill_pixbuf );
+ }
+ else if( background_style == SCALED_STYLE )
+ {
+ scale = MIN(scale_x, scale_y);
+ GdkPixbuf* scaled_pixbuf = gdk_pixbuf_scale_simple(pixbuf, p_width*scale, p_height*scale, GDK_INTERP_BILINEAR);
+ gdk_cairo_set_source_pixbuf(cr, scaled_pixbuf, (width - p_width*scale)/2, (height - p_height*scale)/2);
+ g_object_unref( scaled_pixbuf );
+ }
+ else if( background_style == ZOOM_STYLE )
+ {
+ scale = MAX(scale_x, scale_y);
+ GdkPixbuf* zoom_pixbuf = gdk_pixbuf_scale_simple(pixbuf, p_width*scale, p_height*scale, GDK_INTERP_BILINEAR);
+ gdk_cairo_set_source_pixbuf(cr, zoom_pixbuf, (width - p_width*scale)/2, (height - p_height*scale)/2);
+ g_object_unref( zoom_pixbuf );
+ }
+ else
+ {
+ // if no other style is set the default style of tiled is applied
+ gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
+ pat = cairo_get_source(cr);
+ cairo_pattern_set_extend(pat, CAIRO_EXTEND_REPEAT);
+ }
+ }
+ else
+ {
+ cairo_set_source_rgb(cr, 184.0/256, 215.0/256, 235.0/256);
+ }
+ cairo_fill(cr);
+ cairo_destroy(cr);
}
- cairo_fill(cr);
- cairo_destroy(cr);
/*
GdkGC* gc = gdk_gc_new(evt->window);
@@ -654,11 +728,12 @@
g_free( file );
}
+/*
if( pixbuf )
{
pixmap = gdk_pixmap_new( gdk_get_default_root_window(), gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), -1 );
pixmap_gc = gdk_gc_new(pixmap);
- gdk_draw_pixbuf(pixmap, pixmap_gc, pixbuf,
+ gdk_pixbuf_render_to_drawable(pixbuf, pixmap, pixmap_gc,
0, 0, 0, 0,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),
@@ -668,7 +743,10 @@
g_object_weak_ref( viewport, (GWeakNotify)g_object_unref, pixmap );
g_object_unref(pixmap_gc);
}
- g_signal_connect( viewport, "expose_event", G_CALLBACK(on_viewport_expose), pixmap );
+*/
+ if( pixbuf )
+ g_object_weak_ref( viewport, (GWeakNotify)g_object_unref, pixbuf );
+ g_signal_connect( viewport, "expose_event", G_CALLBACK(on_viewport_expose), pixbuf );
page_data->page_vbox = page_vbox;
page_data->go_up_bar = go_up_bar;
@@ -694,7 +772,7 @@
textdomain (GETTEXT_PACKAGE);
#endif
- context = g_option_context_new("- icon-size background-image");
+ context = g_option_context_new("-");
g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
g_option_context_add_group(context, gtk_get_option_group(TRUE));
if(!g_option_context_parse(context, &argc, &argv, &error))
------------------------------------------------------------------------------
_______________________________________________ Lxde-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/lxde-list
