forked from AuroraMiddleware/gtk
Drop the shape window example in testgtk
Not sure this can be rescued without root window coordinates. It is also somewhat inherently X11-specific.
This commit is contained in:
parent
0eaf861420
commit
535e604b91
225
tests/testgtk.c
225
tests/testgtk.c
@ -5702,230 +5702,6 @@ create_paned_keyboard_navigation (GtkWidget *widget)
|
||||
gtk_widget_show (GTK_WIDGET (window4));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Shaped Windows
|
||||
*/
|
||||
|
||||
typedef struct _cursoroffset {gint x,y;} CursorOffset;
|
||||
|
||||
static void
|
||||
shape_pressed (GtkWidget *widget, GdkEventButton *event)
|
||||
{
|
||||
CursorOffset *p;
|
||||
|
||||
/* ignore double and triple click */
|
||||
if (event->type != GDK_BUTTON_PRESS)
|
||||
return;
|
||||
|
||||
p = g_object_get_data (G_OBJECT (widget), "cursor_offset");
|
||||
p->x = (int) event->x;
|
||||
p->y = (int) event->y;
|
||||
|
||||
gtk_grab_add (widget);
|
||||
gdk_seat_grab (gdk_event_get_seat ((GdkEvent *) event),
|
||||
gtk_widget_get_window (widget),
|
||||
GDK_SEAT_CAPABILITY_ALL_POINTING,
|
||||
TRUE, NULL, (GdkEvent *) event, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
shape_released (GtkWidget *widget,
|
||||
GdkEventButton *event)
|
||||
{
|
||||
gtk_grab_remove (widget);
|
||||
gdk_seat_ungrab (gdk_event_get_seat ((GdkEvent *) event));
|
||||
}
|
||||
|
||||
static void
|
||||
shape_motion (GtkWidget *widget,
|
||||
GdkEventMotion *event)
|
||||
{
|
||||
gint xp, yp;
|
||||
CursorOffset * p;
|
||||
|
||||
p = g_object_get_data (G_OBJECT (widget), "cursor_offset");
|
||||
|
||||
/*
|
||||
* Can't use event->x / event->y here
|
||||
* because I need absolute coordinates.
|
||||
*/
|
||||
gdk_window_get_device_position (gdk_screen_get_root_window (gtk_widget_get_screen (widget)),
|
||||
gdk_event_get_device ((GdkEvent *) event),
|
||||
&xp, &yp, NULL);
|
||||
gtk_window_move (GTK_WINDOW (widget), xp - p->x, yp - p->y);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
shape_create_icon (GdkScreen *screen,
|
||||
char *xpm_file,
|
||||
gint x,
|
||||
gint y,
|
||||
gint px,
|
||||
gint py,
|
||||
gint window_type)
|
||||
{
|
||||
GtkWidget *window;
|
||||
GtkWidget *image;
|
||||
GtkWidget *fixed;
|
||||
CursorOffset* icon_pos;
|
||||
cairo_surface_t *mask;
|
||||
cairo_region_t *mask_region;
|
||||
GdkPixbuf *pixbuf;
|
||||
cairo_t *cr;
|
||||
|
||||
/*
|
||||
* GDK_WINDOW_TOPLEVEL works also, giving you a title border
|
||||
*/
|
||||
window = gtk_window_new (window_type);
|
||||
gtk_window_set_screen (GTK_WINDOW (window), screen);
|
||||
|
||||
fixed = gtk_fixed_new ();
|
||||
gtk_widget_set_size_request (fixed, 100, 100);
|
||||
gtk_container_add (GTK_CONTAINER (window), fixed);
|
||||
gtk_widget_show (fixed);
|
||||
|
||||
gtk_widget_realize (window);
|
||||
|
||||
pixbuf = gdk_pixbuf_new_from_file (xpm_file, NULL);
|
||||
g_assert (pixbuf); /* FIXME: error handling */
|
||||
|
||||
mask = cairo_image_surface_create (CAIRO_FORMAT_A1,
|
||||
gdk_pixbuf_get_width (pixbuf),
|
||||
gdk_pixbuf_get_height (pixbuf));
|
||||
cr = cairo_create (mask);
|
||||
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
|
||||
cairo_paint (cr);
|
||||
cairo_destroy (cr);
|
||||
|
||||
mask_region = gdk_cairo_region_create_from_surface (mask);
|
||||
|
||||
cairo_region_translate (mask_region, px, py);
|
||||
|
||||
image = gtk_image_new_from_pixbuf (pixbuf);
|
||||
gtk_fixed_put (GTK_FIXED (fixed), image, px,py);
|
||||
gtk_widget_show (image);
|
||||
|
||||
gtk_widget_shape_combine_region (window, mask_region);
|
||||
|
||||
cairo_region_destroy (mask_region);
|
||||
cairo_surface_destroy (mask);
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
g_signal_connect (window, "button_press_event",
|
||||
G_CALLBACK (shape_pressed), NULL);
|
||||
g_signal_connect (window, "button_release_event",
|
||||
G_CALLBACK (shape_released), NULL);
|
||||
g_signal_connect (window, "motion_notify_event",
|
||||
G_CALLBACK (shape_motion), NULL);
|
||||
|
||||
icon_pos = g_new (CursorOffset, 1);
|
||||
g_object_set_data (G_OBJECT (window), "cursor_offset", icon_pos);
|
||||
|
||||
gtk_window_move (GTK_WINDOW (window), x, y);
|
||||
gtk_widget_show (window);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
void
|
||||
create_shapes (GtkWidget *widget)
|
||||
{
|
||||
/* Variables used by the Drag/Drop and Shape Window demos */
|
||||
static GtkWidget *modeller = NULL;
|
||||
static GtkWidget *sheets = NULL;
|
||||
static GtkWidget *rings = NULL;
|
||||
static GtkWidget *with_region = NULL;
|
||||
GdkScreen *screen = gtk_widget_get_screen (widget);
|
||||
|
||||
if (!(file_exists ("Modeller.xpm") &&
|
||||
file_exists ("FilesQueue.xpm") &&
|
||||
file_exists ("3DRings.xpm")))
|
||||
return;
|
||||
|
||||
|
||||
if (!modeller)
|
||||
{
|
||||
modeller = shape_create_icon (screen, "Modeller.xpm",
|
||||
440, 140, 0,0, GTK_WINDOW_POPUP);
|
||||
|
||||
g_signal_connect (modeller, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed),
|
||||
&modeller);
|
||||
}
|
||||
else
|
||||
gtk_widget_destroy (modeller);
|
||||
|
||||
if (!sheets)
|
||||
{
|
||||
sheets = shape_create_icon (screen, "FilesQueue.xpm",
|
||||
580, 170, 0,0, GTK_WINDOW_POPUP);
|
||||
|
||||
g_signal_connect (sheets, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed),
|
||||
&sheets);
|
||||
|
||||
}
|
||||
else
|
||||
gtk_widget_destroy (sheets);
|
||||
|
||||
if (!rings)
|
||||
{
|
||||
rings = shape_create_icon (screen, "3DRings.xpm",
|
||||
460, 270, 25,25, GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
g_signal_connect (rings, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed),
|
||||
&rings);
|
||||
}
|
||||
else
|
||||
gtk_widget_destroy (rings);
|
||||
|
||||
if (!with_region)
|
||||
{
|
||||
cairo_region_t *region;
|
||||
gint x, y;
|
||||
|
||||
with_region = shape_create_icon (screen, "3DRings.xpm",
|
||||
460, 270, 25,25, GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
gtk_window_set_decorated (GTK_WINDOW (with_region), FALSE);
|
||||
|
||||
g_signal_connect (with_region, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed),
|
||||
&with_region);
|
||||
|
||||
/* reset shape from mask to a region */
|
||||
x = 0;
|
||||
y = 0;
|
||||
region = cairo_region_create ();
|
||||
|
||||
while (x < 460)
|
||||
{
|
||||
while (y < 270)
|
||||
{
|
||||
GdkRectangle rect;
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
rect.width = 10;
|
||||
rect.height = 10;
|
||||
|
||||
cairo_region_union_rectangle (region, &rect);
|
||||
|
||||
y += 20;
|
||||
}
|
||||
y = 0;
|
||||
x += 20;
|
||||
}
|
||||
|
||||
gdk_window_shape_combine_region (gtk_widget_get_window (with_region),
|
||||
region,
|
||||
0, 0);
|
||||
}
|
||||
else
|
||||
gtk_widget_destroy (with_region);
|
||||
}
|
||||
|
||||
/*
|
||||
* WM Hints demo
|
||||
*/
|
||||
@ -8300,7 +8076,6 @@ struct {
|
||||
{ "rotated text", create_rotated_text },
|
||||
{ "saved position", create_saved_position },
|
||||
{ "scrolled windows", create_scrolled_windows },
|
||||
{ "shapes", create_shapes },
|
||||
{ "size groups", create_size_groups },
|
||||
{ "snapshot", create_snapshot },
|
||||
{ "spinbutton", create_spins },
|
||||
|
Loading…
Reference in New Issue
Block a user