[gtk+/client-side-decorations] Redo region handling
- From: Matthias Clasen <matthiasc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtk+/client-side-decorations] Redo region handling
- Date: Fri, 10 Jul 2009 03:50:18 +0000 (UTC)
commit 8162d296e07647c1061fc74044f8134782d8f197
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jul 9 23:49:05 2009 -0400
Redo region handling
Rewrite the region determination to be more symmetric. And don't
constantly set cursors.
gtk/gtkwindow.c | 98 ++++++++++++++++++++++++++----------------------------
1 files changed, 47 insertions(+), 51 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 9972970..4de7f22 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -108,6 +108,7 @@ enum {
LAST_ARG
};
+/* Must be kept in sync with GdkWindowEdge ! */
typedef enum
{
GTK_WINDOW_REGION_EDGE_NW,
@@ -119,7 +120,7 @@ typedef enum
GTK_WINDOW_REGION_EDGE_S,
GTK_WINDOW_REGION_EDGE_SE,
GTK_WINDOW_REGION_INNER,
- GTK_WINDOW_REGION_TITLE,
+ GTK_WINDOW_REGION_TITLE
} GtkWindowRegion;
typedef struct
@@ -220,6 +221,7 @@ struct _GtkWindowPrivate
GtkWidget *max_button;
GtkWidget *close_button;
GtkWidget *button_box;
+ gint cursor_region;
};
static void gtk_window_dispose (GObject *object);
@@ -1003,6 +1005,7 @@ gtk_window_init (GtkWindow *window)
gtk_window_set_client_side_decorations (window, GDK_DECOR_BORDER | GDK_DECOR_TITLE | GDK_DECOR_MAXIMIZE);
priv->old_decorations = 0;
priv->disable_client_side_decorations = FALSE;
+ priv->cursor_region = -1;
label = gtk_label_new ("");
gtk_widget_show (label);
@@ -5794,47 +5797,39 @@ get_region_type (GtkWindow *window, gint x, gint y)
else
return GTK_WINDOW_REGION_EDGE_W;
}
- else if (x < frame_width + resize_handle)
+ else if (x > widget->allocation.width - frame_width)
{
- if (y < frame_width)
- return GTK_WINDOW_REGION_EDGE_NW;
- else if (y > widget->allocation.height - frame_width)
- return GTK_WINDOW_REGION_EDGE_SW;
- else if (y < frame_width + title_height)
- return GTK_WINDOW_REGION_TITLE;
+ if (y < frame_width + MAX (title_height, resize_handle))
+ return GTK_WINDOW_REGION_EDGE_NE;
+ else if (y > widget->allocation.height - frame_width - resize_handle)
+ return GTK_WINDOW_REGION_EDGE_SE;
else
- return GTK_WINDOW_REGION_INNER;
+ return GTK_WINDOW_REGION_EDGE_E;
}
- else if (x < widget->allocation.width - frame_width - resize_handle)
+ else if (y < frame_width)
{
- if (y < frame_width)
- return GTK_WINDOW_REGION_EDGE_N;
- else if (y > widget->allocation.height - frame_width)
- return GTK_WINDOW_REGION_EDGE_S;
- else if (y < frame_width + title_height)
- return GTK_WINDOW_REGION_TITLE;
+ if (x < frame_width + resize_handle)
+ return GTK_WINDOW_REGION_EDGE_NW;
+ else if (x > widget->allocation.width - frame_width - resize_handle)
+ return GTK_WINDOW_REGION_EDGE_NE;
else
- return GTK_WINDOW_REGION_INNER;
+ return GTK_WINDOW_REGION_EDGE_N;
}
- else if (x < widget->allocation.width - frame_width)
+ else if (y > widget->allocation.height - frame_width)
{
- if (y < frame_width)
- return GTK_WINDOW_REGION_EDGE_NE;
- else if (y > widget->allocation.height - frame_width)
+ if (x < frame_width + resize_handle)
+ return GTK_WINDOW_REGION_EDGE_SW;
+ else if (x > widget->allocation.width - frame_width - resize_handle)
return GTK_WINDOW_REGION_EDGE_SE;
- else if (y < frame_width + title_height)
- return GTK_WINDOW_REGION_TITLE;
else
- return GTK_WINDOW_REGION_INNER;
+ return GTK_WINDOW_REGION_EDGE_S;
}
else
{
- if (y < frame_width + MAX (title_height, resize_handle))
- return GTK_WINDOW_REGION_EDGE_NE;
- else if (y > widget->allocation.height - frame_width - resize_handle)
- return GTK_WINDOW_REGION_EDGE_SE;
+ if (y < frame_width + title_height)
+ return GTK_WINDOW_REGION_TITLE;
else
- return GTK_WINDOW_REGION_EDGE_E;
+ return GTK_WINDOW_REGION_INNER;
}
}
@@ -5896,22 +5891,18 @@ gtk_window_button_press_event (GtkWidget *widget,
if (region == GTK_WINDOW_REGION_TITLE ||
region == GTK_WINDOW_REGION_INNER)
- {
- gtk_window_begin_move_drag (GTK_WINDOW (widget),
+ gtk_window_begin_move_drag (GTK_WINDOW (widget),
+ event->button,
+ event->x_root,
+ event->y_root,
+ event->time);
+ else
+ gtk_window_begin_resize_drag (GTK_WINDOW (widget),
+ edge,
event->button,
event->x_root,
event->y_root,
event->time);
- }
- else if (region <= GTK_WINDOW_REGION_EDGE_SE)
- {
- gtk_window_begin_resize_drag (GTK_WINDOW (widget),
- edge,
- event->button,
- event->x_root,
- event->y_root,
- event->time);
- }
return TRUE;
}
@@ -5944,19 +5935,25 @@ gtk_window_move_focus (GtkWindow *window,
static void
update_cursor_at_position (GtkWidget *widget, gint x, gint y)
{
- GtkWindowRegion region = get_region_type (GTK_WINDOW (widget), x, y);
+ GtkWindow *window = GTK_WINDOW (widget);
+ GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
+ GtkWindowRegion region;
GdkCursorType cursor_type;
GdkCursor *cursor;
- GdkWindowState state = gdk_window_get_state (widget->window);
+ GdkWindowState state;
+
+ region = get_region_type (window, x, y);
+
+ if (region == priv->cursor_region)
+ return;
+
+ state = gdk_window_get_state (widget->window);
- if (region == GTK_WINDOW_REGION_TITLE ||
- region == GTK_WINDOW_REGION_INNER ||
- (state & GDK_WINDOW_STATE_MAXIMIZED) ||
- !GTK_WINDOW (widget)->allow_grow)
+ if ((state & GDK_WINDOW_STATE_MAXIMIZED) || !window->allow_grow)
{
cursor_type = GDK_ARROW;
}
- else if (region <= GTK_WINDOW_REGION_EDGE_SE)
+ else
{
switch (region)
{
@@ -5998,9 +5995,8 @@ update_cursor_at_position (GtkWidget *widget, gint x, gint y)
}
}
- cursor = gdk_cursor_new (cursor_type);
- gdk_window_set_cursor (widget->window,
- cursor);
+ cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), cursor_type);
+ gdk_window_set_cursor (widget->window, cursor);
}
static gint
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]