~cimi/overlay-scrollbar/fix-754736

« back to all changes in this revision

Viewing changes to os/os-scrollbar.c

  • Committer: Andrea Cimitan
  • Date: 2011-04-11 13:57:05 UTC
  • Revision ID: andrea.cimitan@canonical.com-20110411135705-2ipwt132nw3jfx13
Using FocusOut to hide the thumb if needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
/* Width of the proximity effect in pixels. */
36
36
#define PROXIMITY_WIDTH 30
37
37
 
 
38
/* Timeout before setting priv->present_window to FALSE. */
 
39
#define TIMEOUT_PRESENT_WINDOW 400
 
40
 
38
41
/* Timeout before hiding in ms, after leaving the thumb. */
39
42
#define TIMEOUT_THUMB_HIDE 1000
40
43
 
72
75
  gint pointer_y;
73
76
  guint32 source_deactivate_pager_id;
74
77
  guint32 source_hide_thumb_id;
 
78
  guint32 source_present_window_id;
75
79
  guint32 source_unlock_thumb_id;
76
80
};
77
81
 
94
98
static gdouble os_scrollbar_get_wheel_delta (OsScrollbar *scrollbar, GdkScrollDirection direction);
95
99
static void os_scrollbar_hide_thumb (OsScrollbar *scrollbar);
96
100
static gboolean os_scrollbar_hide_thumb_cb (gpointer user_data);
 
101
static gboolean os_scrollbar_present_window_cb (gpointer user_data);
97
102
static gboolean os_scrollbar_unlock_thumb_cb (gpointer user_data);
98
103
static void os_scrollbar_move (OsScrollbar *scrollbar, gint mouse_x, gint mouse_y);
99
104
static void os_scrollbar_move_thumb (OsScrollbar *scrollbar, gint x, gint y);
421
426
}
422
427
 
423
428
static gboolean
 
429
os_scrollbar_present_window_cb (gpointer user_data)
 
430
{
 
431
  OsScrollbar *scrollbar;
 
432
  OsScrollbarPrivate *priv;
 
433
 
 
434
  scrollbar = OS_SCROLLBAR (user_data);
 
435
  priv = scrollbar->priv;
 
436
 
 
437
  priv->present_window = FALSE;
 
438
  priv->source_present_window_id = 0;
 
439
 
 
440
  return FALSE;
 
441
}
 
442
 
 
443
static gboolean
424
444
os_scrollbar_unlock_thumb_cb (gpointer user_data)
425
445
{
426
446
  OsScrollbar *scrollbar;
744
764
 
745
765
          gtk_window_set_transient_for (GTK_WINDOW (widget), NULL);
746
766
 
 
767
          if (priv->source_present_window_id != 0)
 
768
            g_source_remove (priv->source_present_window_id);
 
769
 
 
770
          /* metacity does not emit the configure-event
 
771
           * on changes in stacking (focus/unfocus),
 
772
           * so we need to manually set
 
773
           * priv->present_window to FALSE,
 
774
           * assuming the window is presented.
 
775
           * In X11 event FocusOut and in
 
776
           * toplevel_configure_event_cb the thumb
 
777
           * is hidden only if priv->present_window is FALSE. */
 
778
          priv->source_present_window_id = g_timeout_add (TIMEOUT_PRESENT_WINDOW,
 
779
                                                          os_scrollbar_present_window_cb,
 
780
                                                          scrollbar);
 
781
 
747
782
          if (!priv->motion_notify_event)
748
783
            {
749
784
              if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1193
1228
  if (!priv->present_window)
1194
1229
    gtk_widget_hide (GTK_WIDGET (priv->thumb));
1195
1230
 
1196
 
  priv->present_window = FALSE;
1197
 
 
1198
1231
  priv->lock_position = FALSE;
1199
1232
 
1200
1233
  os_scrollbar_calc_layout_pager (scrollbar, priv->adjustment->value);
1314
1347
                }
1315
1348
            }
1316
1349
        }
 
1350
      
 
1351
      /* this is not properly "nice":
 
1352
       * hide the thumb if the window gets a
 
1353
       * FocusOut event (X11 "kbd focus" removed).
 
1354
       * This is the only way, afaics,
 
1355
       * I could easily know that
 
1356
       * a window with metacity was unfocused. */
 
1357
      if (xevent->type == FocusOut)
 
1358
        {
 
1359
          if (!priv->present_window)
 
1360
            gtk_widget_hide (GTK_WIDGET (priv->thumb));
 
1361
        }
1317
1362
    }
1318
1363
 
1319
1364
  return GDK_FILTER_CONTINUE;
1406
1451
  priv->proximity = FALSE;
1407
1452
  priv->source_deactivate_pager_id = 0;
1408
1453
  priv->source_hide_thumb_id = 0;
 
1454
  priv->source_present_window_id = 0;
1409
1455
  priv->source_unlock_thumb_id = 0;
1410
1456
 
1411
1457
  priv->pager = os_pager_new ();
1438
1484
      priv->source_hide_thumb_id = 0;
1439
1485
    }
1440
1486
 
 
1487
  if (priv->source_present_window_id != 0)
 
1488
    {
 
1489
      g_source_remove (priv->source_present_window_id);
 
1490
      priv->source_present_window_id = 0;
 
1491
    }
 
1492
 
1441
1493
  if (priv->source_unlock_thumb_id != 0)
1442
1494
    {
1443
1495
      g_source_remove (priv->source_unlock_thumb_id);