[vinagre] Updated libview
- From: Jonh Wendell <jwendell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vinagre] Updated libview
- Date: Fri, 25 Jun 2010 22:49:16 +0000 (UTC)
commit 24f0b3ef41e59731ac0395b492c1ba58bf7a791d
Author: Jonh Wendell <jwendell gnome org>
Date: Fri Jun 25 19:40:55 2010 -0300
Updated libview
vinagre/view/autoDrawer.c | 122 +++++++++++++++++++++++++++++++++++++++------
vinagre/view/autoDrawer.h | 2 +
vinagre/view/drawer.c | 32 ++++++++++++
vinagre/view/drawer.h | 1 +
vinagre/view/ovBox.c | 106 ++++++++++++++++++++++++++++-----------
5 files changed, 218 insertions(+), 45 deletions(-)
---
diff --git a/vinagre/view/autoDrawer.c b/vinagre/view/autoDrawer.c
index ccafedc..b92fbda 100644
--- a/vinagre/view/autoDrawer.c
+++ b/vinagre/view/autoDrawer.c
@@ -40,10 +40,12 @@ struct _ViewAutoDrawerPrivate
gboolean inputUngrabbed;
gboolean opened;
+ gboolean forceClosing;
gboolean fill;
gint offset;
+ guint closeConnection;
guint delayConnection;
guint delayValue;
guint overlapPixels;
@@ -80,6 +82,7 @@ ViewAutoDrawerEnforce(ViewAutoDrawer *that, // IN
gboolean animate) // IN
{
double fraction;
+ GtkAllocation allocation;
ViewAutoDrawerPrivate *priv = that->priv;
if (!priv->active) {
@@ -92,8 +95,15 @@ ViewAutoDrawerEnforce(ViewAutoDrawer *that, // IN
g_assert(GTK_IS_WIDGET(priv->over));
ViewOvBox_SetMin(VIEW_OV_BOX(that), priv->noOverlapPixels);
- fraction = priv->opened
- ? 1 : ((double)priv->overlapPixels / priv->over->allocation.height);
+
+ // The forceClosing flag overrides the opened flag.
+ if (priv->opened && !priv->forceClosing) {
+ fraction = 1;
+ } else {
+ gtk_widget_get_allocation (priv->over, &allocation);
+ fraction = ((double)priv->overlapPixels / allocation.height);
+ }
+
if (!animate) {
ViewOvBox_SetFraction(VIEW_OV_BOX(that), fraction);
}
@@ -130,6 +140,33 @@ ViewAutoDrawerOnEnforceDelay(ViewAutoDrawer *that) // IN
/*
*-----------------------------------------------------------------------------
*
+ * ViewAutoDrawerOnCloseDelay --
+ *
+ * Callback fired when the drawer is closed manually. This prevents the
+ * drawer from reopening right away.
+ *
+ * Results:
+ * FALSE to indicate timer should not repeat.
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+static gboolean
+ViewAutoDrawerOnCloseDelay(ViewAutoDrawer *that) // IN
+{
+ that->priv->closeConnection = 0;
+ that->priv->forceClosing = FALSE;
+
+ return FALSE;
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
* ViewAutoDrawerUpdate --
*
* Decide whether an AutoDrawer should be opened or closed, and enforce
@@ -151,6 +188,7 @@ ViewAutoDrawerUpdate(ViewAutoDrawer *that, // IN
ViewAutoDrawerPrivate *priv = that->priv;
GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(that));
GtkWindow *window;
+ GtkAllocation allocation;
if (!toplevel || !gtk_widget_is_toplevel(toplevel)) {
// The autoDrawer cannot function properly without a toplevel.
@@ -181,10 +219,11 @@ ViewAutoDrawerUpdate(ViewAutoDrawer *that, // IN
int y;
gtk_widget_get_pointer(priv->evBox, &x, &y);
+ gtk_widget_get_allocation(priv->evBox, &allocation);
g_assert(gtk_container_get_border_width( GTK_CONTAINER(priv->evBox))
== 0);
- if ( (guint)x < (guint)priv->evBox->allocation.width
- && (guint)y < (guint)priv->evBox->allocation.height) {
+ if ( (guint)x < (guint)allocation.width
+ && (guint)y < (guint)allocation.height) {
priv->opened = TRUE;
}
}
@@ -211,15 +250,15 @@ ViewAutoDrawerUpdate(ViewAutoDrawer *that, // IN
if (!priv->inputUngrabbed) {
GtkWidget *grabbed = NULL;
- if (window->group && window->group->grabs) {
- grabbed = GTK_WIDGET(window->group->grabs->data);
+ if (gtk_window_has_group (window)) {
+ GtkWindowGroup *group = gtk_window_get_group (window);
+ grabbed = gtk_window_group_get_current_grab (group);
}
if (!grabbed) {
grabbed = gtk_grab_get_current();
}
-// g_assert(grabbed);
- if (GTK_IS_MENU(grabbed)) {
+ if (grabbed && GTK_IS_MENU(grabbed)) {
/*
* With cascading menus, the deepest menu owns the grab. Traverse the
* menu hierarchy up until we reach the attach widget for the whole
@@ -254,7 +293,7 @@ ViewAutoDrawerUpdate(ViewAutoDrawer *that, // IN
}
}
- if (gtk_widget_is_ancestor(grabbed, priv->evBox)) {
+ if (grabbed && gtk_widget_is_ancestor(grabbed, priv->evBox)) {
/*
* Override the default 'immediate' to make sure the 'over' widget
* immediately appears along with the widget the grab happens on
@@ -269,7 +308,10 @@ ViewAutoDrawerUpdate(ViewAutoDrawer *that, // IN
if (priv->delayConnection) {
g_source_remove(priv->delayConnection);
}
- if (immediate) {
+
+ if (priv->forceClosing) {
+ ViewAutoDrawerEnforce(that, TRUE);
+ } else if (immediate) {
ViewAutoDrawerEnforce(that, FALSE);
} else {
priv->delayConnection = g_timeout_add(priv->delayValue,
@@ -332,7 +374,7 @@ ViewAutoDrawerOnGrabNotify(GtkWidget *evBox, // IN: Unused
ViewAutoDrawer *that) // IN
{
ViewAutoDrawerPrivate *priv = that->priv;
-
+
priv->inputUngrabbed = ungrabbed;
/*
@@ -481,7 +523,7 @@ ViewAutoDrawerRefreshPacking(ViewAutoDrawer *that) // IN
expand = (that->priv->fill || (that->priv->offset < 0));
fill = that->priv->fill;
padding = (expand || fill) ? 0 : that->priv->offset;
-
+
gtk_box_set_child_packing(GTK_BOX(that), that->priv->evBox,
expand, fill, padding, GTK_PACK_START);
}
@@ -516,6 +558,7 @@ ViewAutoDrawerInit(GTypeInstance *instance, // IN
priv->active = TRUE;
priv->pinned = FALSE;
+ priv->forceClosing = FALSE;
priv->inputUngrabbed = TRUE;
priv->delayConnection = 0;
priv->delayValue = 250;
@@ -679,13 +722,13 @@ ViewAutoDrawer_New(void)
*
* Set the response time of an AutoDrawer in ms., i.e. the time that
* elapses between:
- * - when the AutoDrawer notices a change that can impact the outcome of
+ * - when the AutoDrawer notices a change that can impact the outcome of
* the decision to open or close the drawer,
* and
* - when the AutoDrawer makes such decision.
*
- * Users move the mouse inaccurately. If they temporarily move the mouse in
- * or out of the AutoDrawer for less than the reponse time, their move will
+ * Users move the mouse inaccurately. If they temporarily move the mouse in
+ * or out of the AutoDrawer for less than the reponse time, their move will
* be ignored.
*
* Results:
@@ -887,3 +930,52 @@ ViewAutoDrawer_SetOffset(ViewAutoDrawer *that, // IN
that->priv->offset = offset;
ViewAutoDrawerRefreshPacking(that);
}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ViewAutoDrawer_Close --
+ *
+ * Closes the drawer. This will not unset the pinned state.
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * Drawer state is updated. If there is a focused widget inside the
+ * drawer, unfocus it.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ViewAutoDrawer_Close(ViewAutoDrawer *that) // IN
+{
+ GtkWindow *window;
+ GtkWidget *focus;
+ GtkWidget *toplevel;
+
+ g_return_if_fail(VIEW_IS_AUTODRAWER(that));
+ toplevel = gtk_widget_get_toplevel(GTK_WIDGET(that));
+
+ if (!toplevel || !gtk_widget_is_toplevel(toplevel)) {
+ // The autoDrawer cannot function properly without a toplevel.
+ return;
+ }
+ window = GTK_WINDOW(toplevel);
+
+ focus = gtk_window_get_focus(window);
+ if (focus && gtk_widget_is_ancestor(focus, that->priv->evBox)) {
+ gtk_window_set_focus(window, NULL);
+ }
+
+ that->priv->forceClosing = TRUE;
+ that->priv->closeConnection =
+ g_timeout_add(ViewDrawer_GetCloseTime(&that->parent) +
+ that->priv->delayValue,
+ (GSourceFunc)ViewAutoDrawerOnCloseDelay, that);
+
+ /* This change happens programmatically. Always react to it immediately. */
+ ViewAutoDrawerUpdate(that, TRUE);
+}
diff --git a/vinagre/view/autoDrawer.h b/vinagre/view/autoDrawer.h
index fdd9f36..a2fdd54 100644
--- a/vinagre/view/autoDrawer.h
+++ b/vinagre/view/autoDrawer.h
@@ -83,6 +83,8 @@ void ViewAutoDrawer_SetFill(ViewAutoDrawer *that, gboolean fill);
void ViewAutoDrawer_SetOffset(ViewAutoDrawer *that, gint offset);
+void ViewAutoDrawer_Close(ViewAutoDrawer *that);
+
G_END_DECLS
diff --git a/vinagre/view/drawer.c b/vinagre/view/drawer.c
index 4340e82..aec0728 100644
--- a/vinagre/view/drawer.c
+++ b/vinagre/view/drawer.c
@@ -330,3 +330,35 @@ ViewDrawer_SetGoal(ViewDrawer *that, // IN
priv->timer.pending = TRUE;
}
}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ViewDrawer_GetCloseTime --
+ *
+ * Get the approximate amount of time it will take for this drawer to
+ * open and close, in ms.
+ *
+ * Results:
+ * The time it takes to open or close the drawer.
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+int
+ViewDrawer_GetCloseTime(ViewDrawer *that)
+{
+ ViewDrawerPrivate *priv;
+
+ if (that == NULL) {
+ return 0;
+ }
+
+ priv = that->priv;
+
+ return priv->period * ((int)(1/priv->step) + 1);
+}
diff --git a/vinagre/view/drawer.h b/vinagre/view/drawer.h
index fa55e67..12964a2 100644
--- a/vinagre/view/drawer.h
+++ b/vinagre/view/drawer.h
@@ -74,6 +74,7 @@ GtkWidget *ViewDrawer_New(void);
void ViewDrawer_SetSpeed(ViewDrawer *that, unsigned int period, double step);
void ViewDrawer_SetGoal(ViewDrawer *that, double fraction);
+int ViewDrawer_GetCloseTime(ViewDrawer *that);
G_END_DECLS
diff --git a/vinagre/view/ovBox.c b/vinagre/view/ovBox.c
index 6f3e04e..6e67e59 100644
--- a/vinagre/view/ovBox.c
+++ b/vinagre/view/ovBox.c
@@ -85,6 +85,7 @@ struct _ViewOvBoxPrivate
GtkRequisition overR;
unsigned int min;
double fraction;
+ gint verticalOffset;
};
#define VIEW_OV_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), VIEW_TYPE_OV_BOX, ViewOvBoxPrivate))
@@ -120,7 +121,7 @@ ViewOvBoxInit(GTypeInstance *instance, // IN
that->priv = VIEW_OV_BOX_GET_PRIVATE(that);
priv = that->priv;
- GTK_WIDGET_UNSET_FLAGS(that, GTK_NO_WINDOW);
+ gtk_widget_set_has_window (GTK_WIDGET (that), FALSE);
priv->underWin = NULL;
priv->under = NULL;
@@ -130,6 +131,7 @@ ViewOvBoxInit(GTypeInstance *instance, // IN
priv->overR.width = -1;
priv->min = 0;
priv->fraction = 0;
+ priv->verticalOffset = 0;
}
@@ -152,7 +154,7 @@ ViewOvBoxInit(GTypeInstance *instance, // IN
static void
ViewOvBoxMap(GtkWidget *widget) // IN
{
- gdk_window_show(widget->window);
+ gdk_window_show(gtk_widget_get_window (widget));
GTK_WIDGET_CLASS(parentClass)->map(widget);
}
@@ -176,7 +178,7 @@ ViewOvBoxMap(GtkWidget *widget) // IN
static void
ViewOvBoxUnmap(GtkWidget *widget) // IN
{
- gdk_window_hide(widget->window);
+ gdk_window_hide(gtk_widget_get_window (widget));
GTK_WIDGET_CLASS(parentClass)->unmap(widget);
}
@@ -229,15 +231,15 @@ ViewOvBoxGetUnderGeometry(ViewOvBox *that, // IN
int *height) // OUT
{
unsigned int min;
- GtkAllocation *allocation;
+ GtkAllocation allocation;
min = ViewOvBoxGetActualMin(that);
- allocation = >K_WIDGET(that)->allocation;
+ gtk_widget_get_allocation (GTK_WIDGET(that), &allocation);
*x = 0;
*y = min;
- *width = allocation->width;
- *height = allocation->height - min;
+ *width = allocation.width;
+ *height = allocation.height - min;
}
@@ -269,6 +271,7 @@ ViewOvBoxGetOverGeometry(ViewOvBox *that, // IN
gboolean fill;
guint padding;
unsigned int boxWidth;
+ GtkAllocation allocation;
priv = that->priv;
@@ -289,7 +292,8 @@ ViewOvBoxGetOverGeometry(ViewOvBox *that, // IN
padding = 0;
}
- boxWidth = GTK_WIDGET(that)->allocation.width;
+ gtk_widget_get_allocation(GTK_WIDGET(that), &allocation);
+ boxWidth = allocation.width;
if (!expand) {
*width = MIN(priv->overR.width, boxWidth - padding);
*x = padding;
@@ -302,7 +306,7 @@ ViewOvBoxGetOverGeometry(ViewOvBox *that, // IN
}
*y = (priv->overR.height - ViewOvBoxGetActualMin(that))
- * (priv->fraction - 1);
+ * (priv->fraction - 1) + priv->verticalOffset;
*height = priv->overR.height;
}
@@ -327,11 +331,13 @@ static void
ViewOvBoxSetBackground(ViewOvBox *that) // IN
{
GtkWidget *widget;
+ GtkStyle *style;
widget = GTK_WIDGET(that);
- gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
- gtk_style_set_background(widget->style, that->priv->underWin, GTK_STATE_NORMAL);
- gtk_style_set_background(widget->style, that->priv->overWin, GTK_STATE_NORMAL);
+ style = gtk_widget_get_style (widget);
+ gtk_style_set_background(style, gtk_widget_get_window(widget), GTK_STATE_NORMAL);
+ gtk_style_set_background(style, that->priv->underWin, GTK_STATE_NORMAL);
+ gtk_style_set_background(style, that->priv->overWin, GTK_STATE_NORMAL);
}
@@ -358,9 +364,10 @@ ViewOvBoxRealize(GtkWidget *widget) // IN
ViewOvBoxPrivate *priv;
GdkWindowAttr attributes;
gint mask;
- GtkAllocation *allocation;
+ GtkAllocation allocation;
+ GdkWindow *window;
- GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
+ gtk_widget_set_realized (widget, TRUE);
that = VIEW_OV_BOX(widget);
priv = that->priv;
@@ -372,15 +379,16 @@ ViewOvBoxRealize(GtkWidget *widget) // IN
attributes.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK;
mask = GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_X | GDK_WA_Y;
- allocation = &widget->allocation;
- attributes.x = allocation->x;
- attributes.y = allocation->y;
- attributes.width = allocation->width;
- attributes.height = allocation->height;
- widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
- &attributes, mask);
- gdk_window_set_user_data(widget->window, that);
- widget->style = gtk_style_attach(widget->style, widget->window);
+ gtk_widget_get_allocation(widget, &allocation);
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ window = gdk_window_new(gtk_widget_get_parent_window(widget),
+ &attributes, mask);
+ gtk_widget_set_window(widget, window);
+ gdk_window_set_user_data(window, that);
+ gtk_widget_set_style(widget, gtk_style_attach(gtk_widget_get_style(widget), window));
/*
* The order in which we create the children X window matters: the child
@@ -389,7 +397,7 @@ ViewOvBoxRealize(GtkWidget *widget) // IN
ViewOvBoxGetUnderGeometry(that, &attributes.x, &attributes.y,
&attributes.width, &attributes.height);
- priv->underWin = gdk_window_new(widget->window, &attributes, mask);
+ priv->underWin = gdk_window_new(window, &attributes, mask);
gdk_window_set_user_data(priv->underWin, that);
if (priv->under) {
gtk_widget_set_parent_window(priv->under, priv->underWin);
@@ -398,7 +406,7 @@ ViewOvBoxRealize(GtkWidget *widget) // IN
ViewOvBoxGetOverGeometry(that, &attributes.x, &attributes.y,
&attributes.width, &attributes.height);
- priv->overWin = gdk_window_new(widget->window, &attributes, mask);
+ priv->overWin = gdk_window_new(window, &attributes, mask);
gdk_window_set_user_data(priv->overWin, that);
if (priv->over) {
gtk_widget_set_parent_window(priv->over, priv->overWin);
@@ -524,7 +532,7 @@ ViewOvBoxSizeAllocate(GtkWidget *widget, // IN
GtkAllocation under;
GtkAllocation over;
- widget->allocation = *allocation;
+ gtk_widget_set_allocation (widget, allocation);
that = VIEW_OV_BOX(widget);
priv = that->priv;
@@ -533,8 +541,9 @@ ViewOvBoxSizeAllocate(GtkWidget *widget, // IN
&under.height);
ViewOvBoxGetOverGeometry(that, &over.x, &over.y, &over.width, &over.height);
- if (GTK_WIDGET_REALIZED(widget)) {
- gdk_window_move_resize(widget->window, allocation->x, allocation->y,
+ if (gtk_widget_get_realized(widget)) {
+ gdk_window_move_resize(gtk_widget_get_window(widget),
+ allocation->x, allocation->y,
allocation->width, allocation->height);
gdk_window_move_resize(priv->underWin, under.x, under.y, under.width,
under.height);
@@ -575,7 +584,7 @@ ViewOvBoxStyleSet(GtkWidget *widget, // IN
that = VIEW_OV_BOX(widget);
- if (GTK_WIDGET_REALIZED(widget)) {
+ if (gtk_widget_get_realized(widget)) {
ViewOvBoxSetBackground(that);
}
@@ -865,7 +874,7 @@ ViewOvBox_SetFraction(ViewOvBox *that, // IN
g_return_if_fail(fraction >=0 && fraction <= 1);
that->priv->fraction = fraction;
- if (GTK_WIDGET_REALIZED(that)) {
+ if (gtk_widget_get_realized(GTK_WIDGET (that))) {
int x;
int y;
int width;
@@ -900,3 +909,40 @@ ViewOvBox_GetFraction(ViewOvBox *that)
return that->priv->fraction;
}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ViewOvBox_SetVerticalOffset --
+ *
+ * Set the 'vertical offset' property of a ViewOvBox. Normally, we base
+ * our position on the top edge of the window. This allows us to
+ * be placed somewhere in the middle of a widget.
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ViewOvBox_SetVerticalOffset(ViewOvBox *that, // IN
+ gint offset) // IN
+{
+ g_return_if_fail(that != NULL);
+
+ that->priv->verticalOffset = offset;
+ if (gtk_widget_get_realized(GTK_WIDGET(that))) {
+ int x;
+ int y;
+ int width;
+ int height;
+
+ ViewOvBoxGetOverGeometry(that, &x, &y, &width, &height);
+ gdk_window_move(that->priv->overWin, x, y);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]