~ayatana-scrollbar-team/overlay-scrollbar/0.2

« back to all changes in this revision

Viewing changes to os/os-scrollbar.c

  • Committer: Andrea Cimitan
  • Date: 2012-01-19 17:42:17 UTC
  • mfrom: (332.1.3 ayatana-scrollbar)
  • Revision ID: andrea.cimitan@canonical.com-20120119174217-rka4mydr8ubz8bb4
Merge branch resize-using-thumbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
  OsSide side;
125
125
  OsWindowFilter filter;
126
126
  gboolean active_window;
 
127
  gboolean allow_resize;
127
128
  gboolean deactivable_bar;
128
129
  gboolean hidable_thumb;
129
130
  gboolean window_button_press; /* FIXME(Cimi) to replace with X11 input events. */
1984
1985
  if (priv->event & OS_EVENT_BUTTON_PRESS)
1985
1986
    {
1986
1987
      gint x, y;
 
1988
      gint f_x, f_y;
 
1989
 
 
1990
      f_x = abs (priv->pointer.x - event->x);
 
1991
      f_y = abs (priv->pointer.y - event->y);
1987
1992
 
1988
1993
      /* Use tolerance at the first calls to this motion notify event. */
1989
1994
      if (!(priv->event & OS_EVENT_MOTION_NOTIFY) &&
1990
 
          abs (priv->pointer.x - event->x) <= TOLERANCE_MOTION &&
1991
 
          abs (priv->pointer.y - event->y) <= TOLERANCE_MOTION)
 
1995
          f_x <= TOLERANCE_MOTION &&
 
1996
          f_y <= TOLERANCE_MOTION)
1992
1997
        return FALSE;
1993
1998
 
 
1999
      /* The scrollbar allows resize, and a scrolling is not started yet.
 
2000
       * Decide if the user will start a window resize or a normal scroll. */
 
2001
      if (priv->allow_resize &&
 
2002
          !(priv->event & OS_EVENT_MOTION_NOTIFY))
 
2003
        {
 
2004
          /* Trying to draw the area of interest,
 
2005
           * in the case of a vertical scrollbar.
 
2006
           * Everything is reflected for horizontal scrollbars.
 
2007
           *
 
2008
           * +                           +
 
2009
           *   +       SCROLLING       +
 
2010
           *     +                   +
 
2011
           *     + +               + +
 
2012
           *  R  +   +  +  +  +  +   +  R
 
2013
           *  E  +                   +  E
 
2014
           *  S  +     no action     +  S
 
2015
           *  I  +       taken       +  I
 
2016
           *  Z  +                   +  Z
 
2017
           *  E  +   +  +  +  +  +   +  E
 
2018
           *     + +               + +
 
2019
           *     +                   +
 
2020
           *   +       SCROLLING       +
 
2021
           * +                           +
 
2022
           *
 
2023
           * The diagonal lines are inclined differently, using 0.5 * f_y.
 
2024
           **/
 
2025
          if (((priv->side == OS_SIDE_RIGHT || priv->side == OS_SIDE_LEFT) && f_x > 0.5 * f_y) ||
 
2026
              ((priv->side == OS_SIDE_BOTTOM || priv->side == OS_SIDE_TOP) && f_y > 0.5 * f_x))
 
2027
            {
 
2028
              /* We're either in the 'RESIZE' or in the 'no action taken' area. */
 
2029
              if (((priv->side == OS_SIDE_RIGHT || priv->side == OS_SIDE_LEFT) && f_x > TOLERANCE_DRAG) ||
 
2030
                  ((priv->side == OS_SIDE_BOTTOM || priv->side == OS_SIDE_TOP) && f_y > TOLERANCE_DRAG))
 
2031
                {
 
2032
                  /* We're in the 'RESIZE' area.
 
2033
                   * Set the right resize type and hide the thumb. */
 
2034
                  GdkWindowEdge window_edge;
 
2035
 
 
2036
                  switch (priv->side)
 
2037
                  {
 
2038
                    default:
 
2039
                    case OS_SIDE_RIGHT:
 
2040
                      window_edge = GDK_WINDOW_EDGE_EAST;
 
2041
                      break;
 
2042
                    case OS_SIDE_BOTTOM:
 
2043
                      window_edge = GDK_WINDOW_EDGE_SOUTH;
 
2044
                      break;
 
2045
                    case OS_SIDE_LEFT:
 
2046
                      window_edge = GDK_WINDOW_EDGE_WEST;
 
2047
                      break;
 
2048
                    case OS_SIDE_TOP:
 
2049
                      window_edge = GDK_WINDOW_EDGE_NORTH;
 
2050
                      break;
 
2051
                  }
 
2052
 
 
2053
                  gdk_window_begin_resize_drag (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))),
 
2054
                                                window_edge,
 
2055
                                                1,
 
2056
                                                event->x_root,
 
2057
                                                event->y_root,
 
2058
                                                event->time);
 
2059
                  gtk_widget_hide (widget);
 
2060
                }
 
2061
              /* We're in the 'no action taken' area.
 
2062
               * Skip this event. */
 
2063
              return FALSE;
 
2064
            }
 
2065
 
 
2066
          /* We're in the 'SCROLLING' area.
 
2067
           * Continue processing the event. */
 
2068
        }
 
2069
 
1994
2070
      if (!(priv->event & OS_EVENT_MOTION_NOTIFY))
1995
2071
        {
1996
2072
          /* Check if we can consider the thumb movement connected with the overlay. */
1997
2073
          check_connection (scrollbar);
1998
2074
 
 
2075
          /* It is a scrolling event, set the flag. */
1999
2076
          priv->event |= OS_EVENT_MOTION_NOTIFY;
2000
2077
        }
2001
2078
 
3318
3395
    }
3319
3396
}
3320
3397
 
 
3398
/* Retrieve if the thumb can resize its toplevel window. */
 
3399
static void
 
3400
retrieve_resizability (OsScrollbar *scrollbar)
 
3401
{
 
3402
  GdkWindow *scrollbar_window;
 
3403
  GdkWindow *toplevel_window;
 
3404
  OsScrollbarPrivate *priv;
 
3405
  gint x, y;
 
3406
  gint x_pos, y_pos;
 
3407
 
 
3408
  priv = scrollbar->priv;
 
3409
 
 
3410
  /* By default, they don't allow resize. */
 
3411
  priv->allow_resize = FALSE;
 
3412
 
 
3413
  scrollbar_window = gtk_widget_get_window (GTK_WIDGET (scrollbar));
 
3414
 
 
3415
  if (!scrollbar_window)
 
3416
    return;
 
3417
 
 
3418
  toplevel_window = gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar)));
 
3419
 
 
3420
  gdk_window_get_origin (toplevel_window, &x, &y);
 
3421
 
 
3422
  gdk_window_get_root_coords (scrollbar_window,
 
3423
                              priv->thumb_all.x, priv->thumb_all.y,
 
3424
                              &x_pos, &y_pos);
 
3425
 
 
3426
  /* Check if the thumb is next to a window edge,
 
3427
   * if that's the case, set the allow_resize gboolean. */
 
3428
  switch (priv->side)
 
3429
  {
 
3430
    case OS_SIDE_RIGHT:
 
3431
      if (x + gdk_window_get_width (toplevel_window) - x_pos <= THUMB_WIDTH)
 
3432
        priv->allow_resize = TRUE;
 
3433
      break;
 
3434
    case OS_SIDE_BOTTOM:
 
3435
      if (y + gdk_window_get_height (toplevel_window) - y_pos <= THUMB_WIDTH)
 
3436
        priv->allow_resize = TRUE;
 
3437
      break;
 
3438
    case OS_SIDE_LEFT:
 
3439
      if (x_pos - x <= THUMB_WIDTH)
 
3440
        priv->allow_resize = TRUE;
 
3441
      break;
 
3442
    case OS_SIDE_TOP:
 
3443
      if (y_pos - y <= THUMB_WIDTH)
 
3444
        priv->allow_resize = TRUE;
 
3445
      break;
 
3446
    default:
 
3447
      break;
 
3448
  }
 
3449
}
 
3450
 
3321
3451
static void
3322
3452
os_scrollbar_size_allocate (GtkWidget    *widget,
3323
3453
                            GdkRectangle *allocation)
3396
3526
 
3397
3527
  move_bar (scrollbar);
3398
3528
 
 
3529
  /* Set resizability. */
 
3530
  retrieve_resizability (scrollbar);
 
3531
 
3399
3532
  gtk_widget_set_allocation (widget, allocation);
3400
3533
}
3401
3534