Commit 892ce10c authored by Jim Krehl's avatar Jim Krehl
Browse files

svn path=/branches/version-2/; revision=164



svn path=/branches/version-2/; revision=164
parent c14244a6
/*
* This file is part of libslab.
*
* Copyright (c) 2006 Novell, Inc.
* Copyright (c) 2006, 2007 Novell, Inc.
*
* Libslab is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
......@@ -22,6 +22,8 @@
#include <gtk/gtksettings.h>
#include "libslab-utils.h"
static void double_click_detector_class_init (DoubleClickDetectorClass *);
static void double_click_detector_init (DoubleClickDetector *);
static void double_click_detector_dispose (GObject *);
......@@ -87,37 +89,34 @@ double_click_detector_dispose (GObject * obj)
}
gboolean
double_click_detector_is_double_click (DoubleClickDetector * detector, guint32 event_time,
gboolean auto_update)
double_click_detector_is_double_click (DoubleClickDetector *this, guint32 event_time,
gboolean auto_update)
{
gint32 delta;
g_assert (detector != NULL);
if (event_time <= 0)
event_time = GDK_CURRENT_TIME;
event_time = libslab_get_current_time_millis ();
if (detector->last_click_time <= 0)
{
if (this->last_click_time <= 0) {
if (auto_update)
double_click_detector_update_click_time (detector, event_time);
double_click_detector_update_click_time (this, event_time);
return FALSE;
}
delta = event_time - detector->last_click_time;
delta = event_time - this->last_click_time;
if (auto_update)
double_click_detector_update_click_time (detector, event_time);
double_click_detector_update_click_time (this, event_time);
return delta < detector->double_click_time;
return delta < this->double_click_time;
}
void
double_click_detector_update_click_time (DoubleClickDetector * detector, guint32 event_time)
double_click_detector_update_click_time (DoubleClickDetector *this, guint32 event_time)
{
if (event_time <= 0)
event_time = GDK_CURRENT_TIME;
event_time = libslab_get_current_time_millis ();
detector->last_click_time = event_time;
this->last_click_time = event_time;
}
......@@ -215,19 +215,11 @@ libslab_gnome_desktop_item_open_help (GnomeDesktopItem *item)
guint32
libslab_get_current_time_millis ()
{
GTimeVal time_val;
guint32 time;
GTimeVal t_curr;
g_get_current_time (& t_curr);
time = gtk_get_current_event_time ();
if (! time) {
g_get_current_time (& time_val);
time = (guint32) (1000L * time_val.tv_sec + time_val.tv_usec / 1000L);
}
return time;
return 1000L * t_curr.tv_sec + t_curr.tv_usec / 1000L;
}
void
......
......@@ -113,6 +113,7 @@ static void create_system_section (MainMenuUI *);
static void create_status_section (MainMenuUI *);
static void create_more_buttons (MainMenuUI *);
static void set_panel_button_active (MainMenuUI *, gboolean);
static void select_page (MainMenuUI *, gint);
static void update_limits (MainMenuUI *);
static void connect_to_tile_triggers (MainMenuUI *, TileTable *);
......@@ -124,7 +125,6 @@ static void bind_beagle_search_key (MainMenuUI *);
static void launch_search (MainMenuUI *);
static void grab_pointer_and_keyboard (MainMenuUI *, guint32);
static void panel_button_clicked_cb (GtkButton *, gpointer);
static gboolean panel_button_button_press_cb (GtkWidget *, GdkEventButton *, gpointer);
static void panel_button_drag_data_rcv_cb (GtkWidget *, GdkDragContext *, gint, gint,
GtkSelectionData *, guint, guint, gpointer);
......@@ -310,6 +310,8 @@ create_panel_button (MainMenuUI *this)
GtkWidget *button_root;
GtkWidget *button_parent;
GtkImage *image;
gint i;
......@@ -327,6 +329,8 @@ create_panel_button (MainMenuUI *this)
priv->panel_buttons [PANEL_BUTTON_ORIENT_RIGHT] = glade_xml_get_widget (
priv->panel_button_xml, "slab-main-menu-panel-button-right");
image = GTK_IMAGE (glade_xml_get_widget (panel_button_xml, "image44"));
for (i = 0; i < 4; ++i) {
g_object_set_data (
G_OBJECT (priv->panel_buttons [i]), "double-click-detector",
......@@ -338,10 +342,6 @@ create_panel_button (MainMenuUI *this)
gtk_container_remove (
GTK_CONTAINER (button_parent), priv->panel_buttons [i]);
g_signal_connect (
G_OBJECT (priv->panel_buttons [i]), "clicked",
G_CALLBACK (panel_button_clicked_cb), this);
g_signal_connect (
G_OBJECT (priv->panel_buttons [i]), "button_press_event",
G_CALLBACK (panel_button_button_press_cb), this);
......@@ -685,6 +685,22 @@ create_more_buttons (MainMenuUI *this)
}
}
static void
set_panel_button_active (MainMenuUI *this, gboolean active)
{
MainMenuUIPrivate *priv = PRIVATE (this);
if (active) {
gtk_window_present_with_time (
GTK_WINDOW (priv->slab_window), gtk_get_current_event_time ());
gtk_widget_set_state (priv->panel_button, GTK_STATE_ACTIVE);
}
else {
gtk_widget_hide (priv->slab_window);
gtk_widget_set_state (priv->panel_button, GTK_STATE_NORMAL);
}
}
static void
select_page (MainMenuUI *this, gint page_id)
{
......@@ -796,12 +812,10 @@ connect_to_tile_triggers (MainMenuUI *this, TileTable *table)
static void
hide_slab_if_urgent_close (MainMenuUI *this)
{
MainMenuUIPrivate *priv = PRIVATE (this);
if (! GPOINTER_TO_INT (libslab_get_gconf_value (URGENT_CLOSE_GCONF_KEY)))
return;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->panel_button), FALSE);
set_panel_button_active (this, FALSE);
}
static void
......@@ -1059,45 +1073,25 @@ exit:
xmlFreeDoc (doc);
}
static void
panel_button_clicked_cb (GtkButton *button, gpointer user_data)
static gboolean
panel_button_button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
MainMenuUI *this = MAIN_MENU_UI (user_data);
MainMenuUIPrivate *priv = PRIVATE (this);
GtkToggleButton *toggle = GTK_TOGGLE_BUTTON (button);
DoubleClickDetector *detector;
GTimeVal t_curr;
guint32 t_curr_ms;
gboolean visible;
DoubleClickDetector *dcd;
detector = DOUBLE_CLICK_DETECTOR (
g_object_get_data (G_OBJECT (toggle), "double-click-detector"));
g_get_current_time (& t_curr);
t_curr_ms = 1000 * t_curr.tv_sec + t_curr.tv_usec / 1000;
if (event->button == 1) {
dcd = DOUBLE_CLICK_DETECTOR (
g_object_get_data (G_OBJECT (widget), "double-click-detector"));
visible = GTK_WIDGET_VISIBLE (priv->slab_window);
if (! double_click_detector_is_double_click (dcd, event->time, TRUE))
set_panel_button_active (this, ! GTK_WIDGET_VISIBLE (priv->slab_window));
if (! double_click_detector_is_double_click (detector, t_curr_ms, TRUE)) {
if (! visible)
gtk_window_present_with_time (GTK_WINDOW (priv->slab_window), t_curr_ms);
else
gtk_widget_hide (priv->slab_window);
visible = GTK_WIDGET_VISIBLE (priv->slab_window);
return TRUE;
}
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->panel_button), visible);
}
static gboolean
panel_button_button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
if (event->button != 1)
else
g_signal_stop_emission_by_name (widget, "button_press_event");
return FALSE;
......@@ -1267,18 +1261,18 @@ slab_window_expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer user_d
static gboolean
slab_window_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
MainMenuUIPrivate *priv = PRIVATE (user_data);
MainMenuUI *this = MAIN_MENU_UI (user_data);
switch (event->keyval) {
case GDK_Escape:
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->panel_button), FALSE);
set_panel_button_active (this, FALSE);
return TRUE;
case GDK_W:
case GDK_w:
if (event->state & GDK_CONTROL_MASK) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->panel_button), FALSE);
set_panel_button_active (this, FALSE);
return TRUE;
}
......@@ -1295,17 +1289,31 @@ slab_window_button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer
MainMenuUIPrivate *priv = PRIVATE (this);
GdkWindow *ptr_window;
DoubleClickDetector *dcd;
ptr_window = gdk_window_at_pointer (NULL, NULL);
if (priv->slab_window->window != ptr_window) {
hide_slab_if_urgent_close (this);
if (ptr_window == priv->slab_window->window)
return FALSE;
return TRUE;
/* If the external click happens in the panel button then it's the user turning
* off the menu (or double-clicking. */
if (ptr_window == priv->panel_button->window) {
dcd = DOUBLE_CLICK_DETECTOR (
g_object_get_data (G_OBJECT (priv->panel_button), "double-click-detector"));
if (! double_click_detector_is_double_click (dcd, event->time, TRUE))
set_panel_button_active (this, FALSE);
return FALSE;
}
return FALSE;
hide_slab_if_urgent_close (this);
return TRUE;
}
static void
......@@ -1501,22 +1509,15 @@ more_button_clicked_cb (GtkButton *button, gpointer user_data)
MainMenuUI *this = MAIN_MENU_UI (user_data);
MainMenuUIPrivate *priv = PRIVATE (this);
DoubleClickDetector *detector;
GTimeVal current_time;
guint32 current_time_millis;
DoubleClickDetector *dcd;
GnomeDesktopItem *ditem;
gchar *ditem_id;
detector = DOUBLE_CLICK_DETECTOR (
g_object_get_data (G_OBJECT (button), "double-click-detector"));
g_get_current_time (& current_time);
current_time_millis = 1000 * current_time.tv_sec + current_time.tv_usec / 1000;
dcd = DOUBLE_CLICK_DETECTOR (g_object_get_data (G_OBJECT (button), "double-click-detector"));
if (! double_click_detector_is_double_click (detector, current_time_millis, TRUE)) {
if (! double_click_detector_is_double_click (dcd, gtk_get_current_event_time (), TRUE)) {
if (GTK_WIDGET (button) == priv->more_button [MORE_APPS_BUTTON])
ditem_id = libslab_get_gconf_value (APP_BROWSER_GCONF_KEY);
else
......@@ -1542,8 +1543,7 @@ search_cmd_notify_cb (GConfClient *client, guint conn_id,
static void
panel_menu_open_cb (BonoboUIComponent *component, gpointer user_data, const gchar *verb)
{
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON (PRIVATE (user_data)->panel_button), TRUE);
set_panel_button_active (MAIN_MENU_UI (user_data), TRUE);
}
static void
......@@ -1628,8 +1628,7 @@ panel_applet_change_background_cb (PanelApplet *applet, PanelAppletBackgroundTyp
static void
slab_window_tomboy_bindkey_cb (gchar *key_string, gpointer user_data)
{
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON (PRIVATE (user_data)->panel_button), TRUE);
set_panel_button_active (MAIN_MENU_UI (user_data), TRUE);
}
static void
......
......@@ -994,16 +994,14 @@
<property name="right_padding">0</property>
<child>
<widget class="GtkToggleButton" id="slab-main-menu-panel-button-top">
<widget class="GtkEventBox" id="slab-main-menu-panel-button-top">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">False</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<widget class="GtkHBox" id="panel-button-inner-container">
<property name="border_width">2</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property>
......@@ -1011,7 +1009,7 @@
<child>
<widget class="GtkImage" id="panel-button-icon">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_size">2</property>
<property name="icon_name">gnome-fs-client</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
......@@ -1074,13 +1072,10 @@
<property name="right_padding">0</property>
<child>
<widget class="GtkToggleButton" id="slab-main-menu-panel-button-left">
<widget class="GtkEventBox" id="slab-main-menu-panel-button-left">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">False</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<widget class="GtkVBox" id="vbox42">
......@@ -1116,7 +1111,7 @@
<child>
<widget class="GtkImage" id="image42">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_size">2</property>
<property name="icon_name">gnome-fs-client</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
......@@ -1154,13 +1149,10 @@
<property name="right_padding">0</property>
<child>
<widget class="GtkToggleButton" id="slab-main-menu-panel-button-right">
<widget class="GtkEventBox" id="slab-main-menu-panel-button-right">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">False</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<widget class="GtkVBox" id="vbox43">
......@@ -1171,7 +1163,7 @@
<child>
<widget class="GtkImage" id="image43">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_size">2</property>
<property name="icon_name">gnome-fs-client</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
......@@ -1234,13 +1226,10 @@
<property name="right_padding">0</property>
<child>
<widget class="GtkToggleButton" id="slab-main-menu-panel-button-bottom">
<widget class="GtkEventBox" id="slab-main-menu-panel-button-bottom">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">False</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<widget class="GtkHBox" id="hbox43">
......@@ -1251,7 +1240,7 @@
<child>
<widget class="GtkImage" id="image44">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_size">2</property>
<property name="icon_name">gnome-fs-client</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment