~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/display/gimpdisplayshell-callbacks.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
23
23
#include <gtk/gtk.h>
24
24
#include <gdk/gdkkeysyms.h>
25
25
 
 
26
#include "libgimpmath/gimpmath.h"
26
27
#include "libgimpcolor/gimpcolor.h"
27
28
#include "libgimpwidgets/gimpwidgets.h"
28
29
 
32
33
#include "config/gimpdisplayconfig.h"
33
34
 
34
35
#include "core/gimp.h"
35
 
#include "core/gimpcontainer.h"
36
36
#include "core/gimpcontext.h"
37
37
#include "core/gimpimage.h"
38
38
#include "core/gimpimage-guides.h"
39
 
#include "core/gimpimage-qmask.h"
 
39
#include "core/gimpimage-sample-points.h"
 
40
#include "core/gimpimage-quick-mask.h"
40
41
#include "core/gimplayer.h"
41
42
#include "core/gimptoolinfo.h"
42
43
 
43
44
#include "tools/gimpmovetool.h"
 
45
#include "tools/gimppainttool.h"
44
46
#include "tools/gimptoolcontrol.h"
45
47
#include "tools/tool_manager.h"
46
48
 
59
61
#include "gimpdisplayoptions.h"
60
62
#include "gimpdisplayshell.h"
61
63
#include "gimpdisplayshell-appearance.h"
 
64
#include "gimpdisplayshell-autoscroll.h"
62
65
#include "gimpdisplayshell-callbacks.h"
 
66
#include "gimpdisplayshell-coords.h"
63
67
#include "gimpdisplayshell-cursor.h"
64
68
#include "gimpdisplayshell-draw.h"
65
69
#include "gimpdisplayshell-layer-select.h"
74
78
#include "gimp-intl.h"
75
79
 
76
80
 
77
 
/* #define DEBUG_MOVE_PUSH 1 */
78
 
 
79
 
 
80
81
/*  local function prototypes  */
81
82
 
82
 
static void     gimp_display_shell_vscrollbar_update (GtkAdjustment    *adjustment,
83
 
                                                      GimpDisplayShell *shell);
84
 
static void     gimp_display_shell_hscrollbar_update (GtkAdjustment    *adjustment,
85
 
                                                      GimpDisplayShell *shell);
86
 
 
87
 
static gboolean gimp_display_shell_get_event_coords  (GimpDisplayShell *shell,
88
 
                                                      GdkEvent         *event,
89
 
                                                      GdkDevice        *device,
90
 
                                                      GimpCoords       *coords);
91
 
static void     gimp_display_shell_get_device_coords (GimpDisplayShell *shell,
92
 
                                                      GdkDevice        *device,
93
 
                                                      GimpCoords       *coords);
94
 
static void     gimp_display_shell_get_time_coords   (GimpDisplayShell *shell,
95
 
                                                      GdkDevice        *device,
96
 
                                                      GdkTimeCoord     *event,
97
 
                                                      GimpCoords       *coords);
98
 
static gboolean gimp_display_shell_get_event_state   (GimpDisplayShell *shell,
99
 
                                                      GdkEvent         *event,
100
 
                                                      GdkDevice        *device,
101
 
                                                      GdkModifierType  *state);
102
 
static void     gimp_display_shell_get_device_state  (GimpDisplayShell *shell,
103
 
                                                      GdkDevice        *device,
104
 
                                                      GdkModifierType  *state);
 
83
static void       gimp_display_shell_vscrollbar_update (GtkAdjustment    *adjustment,
 
84
                                                        GimpDisplayShell *shell);
 
85
static void       gimp_display_shell_hscrollbar_update (GtkAdjustment    *adjustment,
 
86
                                                        GimpDisplayShell *shell);
105
87
 
106
88
static GdkModifierType
107
 
                gimp_display_shell_key_to_state      (gint              key);
 
89
                  gimp_display_shell_key_to_state      (gint              key);
108
90
 
109
 
static GdkEvent * gimp_display_shell_compress_motion (GimpDisplayShell *shell);
 
91
static GdkEvent * gimp_display_shell_compress_motion   (GimpDisplayShell *shell);
110
92
 
111
93
 
112
94
/*  public functions  */
116
98
                           GdkEvent         *event,
117
99
                           GimpDisplayShell *shell)
118
100
{
119
 
  Gimp        *gimp;
120
 
  gboolean     set_display = FALSE;
 
101
  Gimp     *gimp;
 
102
  gboolean  set_display = FALSE;
121
103
 
122
104
  /*  are we in destruction?  */
123
 
  if (! shell->gdisp || ! shell->gdisp->shell)
 
105
  if (! shell->display || ! shell->display->shell)
124
106
    return TRUE;
125
107
 
126
 
  gimp = shell->gdisp->gimage->gimp;
 
108
  gimp = shell->display->image->gimp;
127
109
 
128
110
  switch (event->type)
129
111
    {
141
123
         */
142
124
        if (kevent->state & GDK_BUTTON1_MASK)
143
125
          {
 
126
            if (kevent->keyval == GDK_Shift_L   ||
 
127
                kevent->keyval == GDK_Shift_R   ||
 
128
                kevent->keyval == GDK_Control_L ||
 
129
                kevent->keyval == GDK_Control_R ||
 
130
                kevent->keyval == GDK_Alt_L     ||
 
131
                kevent->keyval == GDK_Alt_R)
 
132
              {
 
133
                break;
 
134
              }
 
135
 
144
136
            if (event->type == GDK_KEY_PRESS)
145
137
              {
146
138
                if (kevent->keyval == GDK_space && shell->space_release_pending)
206
198
 
207
199
    case GDK_WINDOW_STATE:
208
200
      {
209
 
        GdkEventWindowState *sevent = (GdkEventWindowState *) event;
 
201
        GdkEventWindowState *sevent = (GdkEventWindowState *) event;
210
202
        GimpDisplayOptions  *options;
211
203
        gboolean             fullscreen;
212
204
        GimpActionGroup     *group;
213
205
 
214
 
        shell->window_state = sevent->new_window_state;
 
206
        shell->window_state = sevent->new_window_state;
215
207
 
216
208
        if (! (sevent->changed_mask & GDK_WINDOW_STATE_FULLSCREEN))
217
209
          break;
218
210
 
219
211
        fullscreen = gimp_display_shell_get_fullscreen (shell);
220
212
 
 
213
        gtk_widget_set_name (GTK_WIDGET (shell->menubar),
 
214
                             fullscreen ? "gimp-menubar-fullscreen" : NULL);
 
215
 
221
216
        options = fullscreen ? shell->fullscreen_options : shell->options;
222
217
 
223
 
        gimp_display_shell_set_show_menubar    (shell,
224
 
                                                options->show_menubar);
225
 
        gimp_display_shell_set_show_rulers     (shell,
226
 
                                                options->show_rulers);
227
 
        gimp_display_shell_set_show_scrollbars (shell,
228
 
                                                options->show_scrollbars);
229
 
        gimp_display_shell_set_show_statusbar  (shell,
230
 
                                                options->show_statusbar);
231
 
        gimp_display_shell_set_show_selection  (shell,
232
 
                                                options->show_selection);
233
 
        gimp_display_shell_set_show_layer      (shell,
234
 
                                                options->show_layer_boundary);
235
 
        gimp_display_shell_set_show_guides     (shell,
236
 
                                                options->show_guides);
237
 
        gimp_display_shell_set_show_grid       (shell,
238
 
                                                options->show_grid);
239
 
        gimp_display_shell_set_padding         (shell,
240
 
                                                options->padding_mode,
241
 
                                                &options->padding_color);
 
218
        gimp_display_shell_set_show_menubar       (shell,
 
219
                                                   options->show_menubar);
 
220
        gimp_display_shell_set_show_rulers        (shell,
 
221
                                                   options->show_rulers);
 
222
        gimp_display_shell_set_show_scrollbars    (shell,
 
223
                                                   options->show_scrollbars);
 
224
        gimp_display_shell_set_show_statusbar     (shell,
 
225
                                                   options->show_statusbar);
 
226
        gimp_display_shell_set_show_selection     (shell,
 
227
                                                   options->show_selection);
 
228
        gimp_display_shell_set_show_layer         (shell,
 
229
                                                   options->show_layer_boundary);
 
230
        gimp_display_shell_set_show_guides        (shell,
 
231
                                                   options->show_guides);
 
232
        gimp_display_shell_set_show_grid          (shell,
 
233
                                                   options->show_grid);
 
234
        gimp_display_shell_set_show_sample_points (shell,
 
235
                                                   options->show_sample_points);
 
236
        gimp_display_shell_set_padding            (shell,
 
237
                                                   options->padding_mode,
 
238
                                                   &options->padding_color);
242
239
 
243
240
        group = gimp_ui_manager_get_action_group (shell->menubar_manager,
244
241
                                                  "view");
245
242
        gimp_action_group_set_action_active (group, "view-fullscreen",
246
243
                                             fullscreen);
247
244
 
248
 
        if (shell->gdisp ==
 
245
        if (shell->display ==
249
246
            gimp_context_get_display (gimp_get_user_context (gimp)))
250
247
          {
251
248
            group = gimp_ui_manager_get_action_group (shell->popup_manager,
262
259
 
263
260
  if (set_display)
264
261
    {
265
 
      Gimp *gimp = shell->gdisp->gimage->gimp;
 
262
      Gimp *gimp = shell->display->image->gimp;
266
263
 
267
264
      /*  Setting the context's display automatically sets the image, too  */
268
 
      gimp_context_set_display (gimp_get_user_context (gimp), shell->gdisp);
 
265
      gimp_context_set_display (gimp_get_user_context (gimp), shell->display);
269
266
    }
270
267
 
271
268
  return FALSE;
276
273
                                   GimpDisplayShell *shell)
277
274
{
278
275
  GimpDisplayConfig     *config;
279
 
  GimpDisplay           *gdisp;
 
276
  GimpDisplay           *display;
280
277
  GimpCanvasPaddingMode  padding_mode;
281
278
  GimpRGB                padding_color;
282
279
 
283
 
  gdisp  = shell->gdisp;
284
 
  config = GIMP_DISPLAY_CONFIG (gdisp->gimage->gimp->config);
 
280
  display = shell->display;
 
281
  config  = GIMP_DISPLAY_CONFIG (display->image->gimp->config);
285
282
 
286
283
  gtk_widget_grab_focus (shell->canvas);
287
284
 
294
291
  shell->disp_height = canvas->allocation.height;
295
292
 
296
293
  /*  set up the scrollbar observers  */
297
 
  g_signal_connect (shell->hsbdata, "value_changed",
 
294
  g_signal_connect (shell->hsbdata, "value-changed",
298
295
                    G_CALLBACK (gimp_display_shell_hscrollbar_update),
299
296
                    shell);
300
 
  g_signal_connect (shell->vsbdata, "value_changed",
 
297
  g_signal_connect (shell->vsbdata, "value-changed",
301
298
                    G_CALLBACK (gimp_display_shell_vscrollbar_update),
302
299
                    shell);
303
300
 
319
316
                                         GimpDisplayShell *shell)
320
317
{
321
318
  /*  are we in destruction?  */
322
 
  if (! shell->gdisp || ! shell->gdisp->shell)
 
319
  if (! shell->display || ! shell->display->shell)
323
320
    return;
324
321
 
325
322
  if ((shell->disp_width  != allocation->width) ||
331
328
          allocation->width  > 64 &&
332
329
          allocation->height > 64)
333
330
        {
334
 
          gdouble scale = shell->scale;
 
331
          gdouble scale = gimp_zoom_model_get_factor (shell->zoom);
335
332
          gint    offset_x;
336
333
          gint    offset_y;
337
334
 
346
343
          offset_x = UNSCALEX (shell, shell->offset_x);
347
344
          offset_y = UNSCALEX (shell, shell->offset_y);
348
345
 
349
 
          shell->scale    = scale;
 
346
          gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale);
 
347
 
350
348
          shell->offset_x = SCALEX (shell, offset_x);
351
349
          shell->offset_y = SCALEY (shell, offset_y);
352
350
        }
371
369
  gint          i;
372
370
 
373
371
  /*  are we in destruction?  */
374
 
  if (! shell->gdisp || ! shell->gdisp->shell)
 
372
  if (! shell->display || ! shell->display->shell)
375
373
    return TRUE;
376
374
 
377
375
  /*  If the call to gimp_display_shell_pause() would cause a redraw,
422
420
  /* draw the transform tool preview */
423
421
  gimp_display_shell_preview_transform (shell);
424
422
 
 
423
  /* draw the grid */
 
424
  gimp_display_shell_draw_grid (shell, &eevent->area);
 
425
 
425
426
  /* draw the guides */
426
427
  gimp_display_shell_draw_guides (shell);
427
428
 
428
 
  /* draw the grid */
429
 
  gimp_display_shell_draw_grid (shell, &eevent->area);
 
429
  /* draw the sample points */
 
430
  gimp_display_shell_draw_sample_points (shell);
430
431
 
431
432
  /* and the cursor (if we have a software cursor) */
432
433
  gimp_display_shell_draw_cursor (shell);
433
434
 
434
435
  /* restart (and recalculate) the selection boundaries */
435
 
  gimp_display_shell_selection_start (shell->select, TRUE);
 
436
  gimp_display_shell_selection_control (shell, GIMP_SELECTION_ON);
436
437
 
437
438
  gimp_display_shell_resume (shell);
438
439
 
444
445
{
445
446
  GdkDevice *current_device;
446
447
 
447
 
  current_device = gimp_devices_get_current (shell->gdisp->gimage->gimp);
 
448
  current_device = gimp_devices_get_current (shell->display->image->gimp);
448
449
 
449
450
  shell->draw_cursor = ! current_device->has_cursor;
450
451
}
451
452
 
 
453
static void
 
454
gimp_display_shell_start_scrolling (GimpDisplayShell *shell,
 
455
                                    gint              x,
 
456
                                    gint              y)
 
457
{
 
458
  g_return_if_fail (! shell->scrolling);
 
459
 
 
460
  shell->scrolling      = TRUE;
 
461
  shell->scroll_start_x = x + shell->offset_x;
 
462
  shell->scroll_start_y = y + shell->offset_y;
 
463
 
 
464
  gimp_display_shell_set_override_cursor (shell, GDK_FLEUR);
 
465
 
 
466
  gtk_grab_add (shell->canvas);
 
467
}
 
468
 
 
469
static void
 
470
gimp_display_shell_stop_scrolling (GimpDisplayShell *shell)
 
471
{
 
472
  g_return_if_fail (shell->scrolling);
 
473
 
 
474
  shell->scrolling      = FALSE;
 
475
  shell->scroll_start_x = 0;
 
476
  shell->scroll_start_y = 0;
 
477
 
 
478
  gimp_display_shell_unset_override_cursor (shell);
 
479
 
 
480
  gtk_grab_remove (shell->canvas);
 
481
}
 
482
 
 
483
static void
 
484
gimp_display_shell_space_pressed (GimpDisplayShell *shell,
 
485
                                  GdkModifierType   state,
 
486
                                  guint32           time)
 
487
{
 
488
  Gimp *gimp = shell->display->image->gimp;
 
489
 
 
490
  if (shell->space_pressed)
 
491
    return;
 
492
 
 
493
  switch (GIMP_DISPLAY_CONFIG (gimp->config)->space_bar_action)
 
494
    {
 
495
    case GIMP_SPACE_BAR_ACTION_NONE:
 
496
      return;
 
497
 
 
498
    case GIMP_SPACE_BAR_ACTION_PAN:
 
499
      {
 
500
        GimpCoords coords;
 
501
 
 
502
        gimp_display_shell_get_device_coords (shell,
 
503
                                              gimp_devices_get_current (gimp),
 
504
                                              &coords);
 
505
 
 
506
        gimp_display_shell_start_scrolling (shell, coords.x, coords.y);
 
507
 
 
508
        gdk_pointer_grab (shell->canvas->window, FALSE,
 
509
                          GDK_POINTER_MOTION_MASK |
 
510
                          GDK_POINTER_MOTION_HINT_MASK,
 
511
                          NULL, NULL, time);
 
512
      }
 
513
      break;
 
514
 
 
515
    case GIMP_SPACE_BAR_ACTION_MOVE:
 
516
      {
 
517
        GimpTool *active_tool = tool_manager_get_active (gimp);
 
518
 
 
519
        if (! active_tool || GIMP_IS_MOVE_TOOL (active_tool))
 
520
          return;
 
521
 
 
522
        shell->space_shaded_tool =
 
523
          gimp_object_get_name (GIMP_OBJECT (active_tool->tool_info));
 
524
 
 
525
        gimp_context_set_tool (gimp_get_user_context (gimp),
 
526
                               gimp_get_tool_info (gimp, "gimp-move-tool"));
 
527
 
 
528
        tool_manager_focus_display_active (gimp, shell->display);
 
529
        tool_manager_modifier_state_active (gimp, state, shell->display);
 
530
      }
 
531
      break;
 
532
    }
 
533
 
 
534
  gdk_keyboard_grab (shell->canvas->window, FALSE, time);
 
535
 
 
536
  shell->space_pressed = TRUE;
 
537
}
 
538
 
 
539
static void
 
540
gimp_display_shell_space_released (GimpDisplayShell *shell,
 
541
                                   GdkModifierType   state,
 
542
                                   guint32           time)
 
543
{
 
544
  Gimp *gimp = shell->display->image->gimp;
 
545
 
 
546
  if (! shell->space_pressed && ! shell->space_release_pending)
 
547
    return;
 
548
 
 
549
  switch (GIMP_DISPLAY_CONFIG (gimp->config)->space_bar_action)
 
550
    {
 
551
    case GIMP_SPACE_BAR_ACTION_NONE:
 
552
      break;
 
553
 
 
554
    case GIMP_SPACE_BAR_ACTION_PAN:
 
555
      gimp_display_shell_stop_scrolling (shell);
 
556
      gdk_display_pointer_ungrab (gtk_widget_get_display (shell->canvas), time);
 
557
      break;
 
558
 
 
559
    case GIMP_SPACE_BAR_ACTION_MOVE:
 
560
      gimp_context_set_tool (gimp_get_user_context (gimp),
 
561
                             gimp_get_tool_info (gimp,
 
562
                                                 shell->space_shaded_tool));
 
563
      shell->space_shaded_tool = NULL;
 
564
 
 
565
      tool_manager_focus_display_active (gimp, shell->display);
 
566
      tool_manager_modifier_state_active (gimp, state, shell->display);
 
567
      break;
 
568
    }
 
569
 
 
570
  gdk_display_keyboard_ungrab (gtk_widget_get_display (shell->canvas), time);
 
571
 
 
572
  shell->space_pressed         = FALSE;
 
573
  shell->space_release_pending = FALSE;
 
574
}
 
575
 
452
576
gboolean
453
577
gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
454
578
                                       GdkEvent         *event,
455
579
                                       GimpDisplayShell *shell)
456
580
{
457
 
  GimpDisplay     *gdisp;
458
 
  GimpImage       *gimage;
459
 
  Gimp            *gimp;
460
 
  GdkDisplay      *gdk_display;
461
 
  GimpTool        *active_tool;
462
 
  GimpCoords       display_coords;
463
 
  GimpCoords       image_coords;
464
 
  GdkModifierType  state;
465
 
  guint32          time;
466
 
  gboolean         return_val    = FALSE;
467
 
  gboolean         update_cursor = FALSE;
468
 
 
469
 
  static GimpToolInfo *space_shaded_tool = NULL;
470
 
 
471
 
  if (! canvas->window)
472
 
    {
473
 
      g_warning ("%s: called unrealized", G_STRFUNC);
474
 
      return FALSE;
475
 
    }
 
581
  GimpDisplay         *display;
 
582
  GimpImage           *image;
 
583
  Gimp                *gimp;
 
584
  GdkDisplay          *gdk_display;
 
585
  GimpTool            *active_tool;
 
586
  GimpCoords           display_coords;
 
587
  GimpCoords           image_coords;
 
588
  GdkModifierType      state;
 
589
  guint32              time;
 
590
  gboolean             return_val       = FALSE;
 
591
  gboolean             update_sw_cursor = FALSE;
 
592
 
 
593
  g_return_val_if_fail (GTK_WIDGET_REALIZED (canvas), FALSE);
476
594
 
477
595
  /*  are we in destruction?  */
478
 
  if (! shell->gdisp || ! shell->gdisp->shell)
 
596
  if (! shell->display || ! shell->display->shell)
479
597
    return TRUE;
480
598
 
481
599
  /*  set the active display before doing any other canvas event processing  */
482
600
  if (gimp_display_shell_events (canvas, event, shell))
483
601
    return TRUE;
484
602
 
485
 
  gdisp  = shell->gdisp;
486
 
  gimage = gdisp->gimage;
487
 
  gimp   = gimage->gimp;
 
603
  display = shell->display;
 
604
  image   = display->image;
 
605
  gimp    = image->gimp;
488
606
 
489
607
  gdk_display = gtk_widget_get_display (canvas);
490
608
 
503
621
  time = gdk_event_get_time (event);
504
622
 
505
623
  /*  GimpCoords passed to tools are ALWAYS in image coordinates  */
506
 
  gimp_display_shell_untransform_coords (shell,
507
 
                                         &display_coords,
508
 
                                         &image_coords);
 
624
  gimp_display_shell_untransform_coordinate (shell,
 
625
                                             &display_coords,
 
626
                                             &image_coords);
509
627
 
510
628
  active_tool = tool_manager_get_active (gimp);
511
629
 
512
 
  if (active_tool && gimp_tool_control_auto_snap_to (active_tool->control))
 
630
  if (active_tool && gimp_tool_control_get_snap_to (active_tool->control))
513
631
    {
514
632
      gint x, y, width, height;
515
633
 
516
 
      gimp_tool_control_snap_offsets (active_tool->control,
517
 
                                      &x, &y, &width, &height);
 
634
      gimp_tool_control_get_snap_offsets (active_tool->control,
 
635
                                          &x, &y, &width, &height);
518
636
 
519
637
      if (gimp_display_shell_snap_coords (shell,
520
638
                                          &image_coords,
521
639
                                          &image_coords,
522
640
                                          x, y, width, height))
523
641
        {
524
 
          update_cursor = TRUE;
 
642
          update_sw_cursor = TRUE;
525
643
        }
526
644
    }
527
645
 
534
652
        if (cevent->mode != GDK_CROSSING_NORMAL)
535
653
          return TRUE;
536
654
 
537
 
        update_cursor = TRUE;
 
655
        update_sw_cursor = TRUE;
538
656
 
539
657
        tool_manager_oper_update_active (gimp,
540
658
                                         &image_coords, state,
541
 
                                         gdisp);
 
659
                                         shell->proximity,
 
660
                                         display);
542
661
      }
543
662
      break;
544
663
 
554
673
 
555
674
        tool_manager_oper_update_active (gimp,
556
675
                                         &image_coords, state,
557
 
                                         gdisp);
 
676
                                         shell->proximity,
 
677
                                         display);
558
678
      }
559
679
      break;
560
680
 
561
681
    case GDK_PROXIMITY_IN:
562
682
      tool_manager_oper_update_active (gimp,
563
683
                                       &image_coords, state,
564
 
                                       gdisp);
 
684
                                       shell->proximity,
 
685
                                       display);
565
686
      break;
566
687
 
567
688
    case GDK_PROXIMITY_OUT:
570
691
 
571
692
      tool_manager_oper_update_active (gimp,
572
693
                                       &image_coords, state,
573
 
                                       gdisp);
 
694
                                       shell->proximity,
 
695
                                       display);
574
696
      break;
575
697
 
576
698
    case GDK_FOCUS_CHANGE:
588
710
             */
589
711
            if (! shell->button_press_before_focus)
590
712
              {
591
 
                tool_manager_focus_display_active (gimp, gdisp);
592
 
                tool_manager_modifier_state_active (gimp, state, gdisp);
 
713
                tool_manager_focus_display_active (gimp, display);
 
714
                tool_manager_modifier_state_active (gimp, state, display);
593
715
 
594
716
                tool_manager_oper_update_active (gimp,
595
717
                                                 &image_coords, state,
596
 
                                                 gdisp);
 
718
                                                 shell->proximity,
 
719
                                                 display);
597
720
              }
598
721
          }
599
722
        else
610
733
 
611
734
            tool_manager_oper_update_active (gimp,
612
735
                                             &image_coords, 0,
613
 
                                             gdisp);
 
736
                                             shell->proximity,
 
737
                                             display);
614
738
          }
615
739
 
616
740
        /*  stop the signal because otherwise gtk+ exposes the whole
630
754
            /*  in "click to focus" mode, the BUTTON_PRESS arrives before
631
755
             *  FOCUS_IN, so we have to update the tool's modifier state here
632
756
             */
633
 
            tool_manager_focus_display_active (gimp, gdisp);
634
 
            tool_manager_modifier_state_active (gimp, state, gdisp);
 
757
            tool_manager_focus_display_active (gimp, display);
 
758
            tool_manager_modifier_state_active (gimp, state, display);
635
759
 
636
760
            tool_manager_oper_update_active (gimp,
637
761
                                             &image_coords, state,
638
 
                                             gdisp);
 
762
                                             shell->proximity,
 
763
                                             display);
639
764
 
640
765
            active_tool = tool_manager_get_active (gimp);
641
766
 
642
767
            if (active_tool)
643
768
              {
644
 
                if ((! gimp_image_is_empty (gimage) ||
645
 
                     gimp_tool_control_handles_empty_image (active_tool->control)) &&
 
769
                if ((! gimp_image_is_empty (image) ||
 
770
                     gimp_tool_control_get_handle_empty_image (active_tool->control)) &&
646
771
                    (bevent->button == 1 ||
647
772
                     bevent->button == 2 ||
648
773
                     bevent->button == 3))
649
774
                  {
650
775
                    tool_manager_cursor_update_active (gimp,
651
776
                                                       &image_coords, state,
652
 
                                                       gdisp);
 
777
                                                       display);
653
778
                  }
654
 
                else if (gimp_image_is_empty (gimage))
 
779
                else if (gimp_image_is_empty (image) &&
 
780
                         ! gimp_tool_control_get_handle_empty_image (active_tool->control))
655
781
                  {
656
782
                    gimp_display_shell_set_cursor (shell,
657
 
                                                   GIMP_CURSOR_BAD,
 
783
                                                   GIMP_CURSOR_MOUSE,
658
784
                                                   gimp_tool_control_get_tool_cursor (active_tool->control),
659
 
                                                   GIMP_CURSOR_MODIFIER_NONE);
 
785
                                                   GIMP_CURSOR_MODIFIER_BAD);
660
786
                  }
661
787
              }
662
788
            else
663
789
              {
664
790
                gimp_display_shell_set_cursor (shell,
665
 
                                               GIMP_CURSOR_BAD,
 
791
                                               GIMP_CURSOR_MOUSE,
666
792
                                               GIMP_TOOL_CURSOR_NONE,
667
 
                                               GIMP_CURSOR_MODIFIER_NONE);
 
793
                                               GIMP_CURSOR_MODIFIER_BAD);
668
794
              }
669
795
 
670
796
            shell->button_press_before_focus = TRUE;
676
802
          }
677
803
 
678
804
        /*  ignore new mouse events  */
679
 
        if (gimp->busy)
 
805
        if (gimp->busy || shell->scrolling)
680
806
          return TRUE;
681
807
 
682
808
        active_tool = tool_manager_get_active (gimp);
690
816
 
691
817
            if (active_tool &&
692
818
                (! GIMP_DISPLAY_CONFIG (gimp->config)->perfect_mouse ||
693
 
                 (gimp_tool_control_motion_mode (active_tool->control) !=
 
819
                 (gimp_tool_control_get_motion_mode (active_tool->control) !=
694
820
                  GIMP_MOTION_MODE_EXACT)))
695
821
              {
696
822
                /*  don't request motion hins for XInput devices because
700
826
                if (gimp_devices_get_current (gimp) ==
701
827
                    gdk_display_get_core_pointer (gdk_display))
702
828
                  {
703
 
                    event_mask |= (GDK_POINTER_MOTION_HINT_MASK);
 
829
                    event_mask |= GDK_POINTER_MOTION_HINT_MASK;
704
830
                  }
705
831
              }
706
832
 
711
837
              gdk_keyboard_grab (canvas->window, FALSE, time);
712
838
 
713
839
            if (active_tool &&
714
 
                (! gimp_image_is_empty (gimage) ||
715
 
                 gimp_tool_control_handles_empty_image (active_tool->control)))
 
840
                (! gimp_image_is_empty (image) ||
 
841
                 gimp_tool_control_get_handle_empty_image (active_tool->control)))
716
842
              {
717
843
                gboolean initialized = TRUE;
718
844
 
720
846
                 */
721
847
                if (! active_tool->drawable)
722
848
                  {
723
 
                    initialized = tool_manager_initialize_active (gimp, gdisp);
 
849
                    initialized = tool_manager_initialize_active (gimp,
 
850
                                                                  display);
724
851
                  }
725
852
                else if ((active_tool->drawable !=
726
 
                          gimp_image_active_drawable (gimage)) &&
727
 
                         ! gimp_tool_control_preserve (active_tool->control))
 
853
                          gimp_image_active_drawable (image)) &&
 
854
                         ! gimp_tool_control_get_preserve (active_tool->control))
728
855
                  {
729
856
                    /*  create a new one, deleting the current
730
857
                     */
731
858
                    gimp_context_tool_changed (gimp_get_user_context (gimp));
732
859
 
733
 
                    initialized = tool_manager_initialize_active (gimp, gdisp);
 
860
                    initialized = tool_manager_initialize_active (gimp, display);
734
861
                  }
735
862
 
736
863
                if (initialized)
737
864
                  {
738
865
                    tool_manager_button_press_active (gimp,
739
 
                                                      &image_coords, time, state,
740
 
                                                      gdisp);
 
866
                                                      &image_coords,
 
867
                                                      time, state, display);
741
868
 
742
869
                    shell->last_motion_time = bevent->time;
743
870
                  }
746
873
 
747
874
          case 2:
748
875
            state |= GDK_BUTTON2_MASK;
749
 
 
750
 
            shell->scrolling      = TRUE;
751
 
            shell->scroll_start_x = bevent->x + shell->offset_x;
752
 
            shell->scroll_start_y = bevent->y + shell->offset_y;
753
 
 
754
 
            gtk_grab_add (canvas);
755
 
 
756
 
            gimp_display_shell_set_override_cursor (shell, GDK_FLEUR);
 
876
            gimp_display_shell_start_scrolling (shell, bevent->x, bevent->y);
757
877
            break;
758
878
 
759
879
          case 3:
775
895
      {
776
896
        GdkEventButton *bevent = (GdkEventButton *) event;
777
897
 
 
898
        gimp_display_shell_autoscroll_stop (shell);
 
899
 
778
900
        if (gimp->busy)
779
901
          return TRUE;
780
902
 
793
915
            gtk_grab_add (canvas);
794
916
 
795
917
            if (active_tool &&
796
 
                (! gimp_image_is_empty (gimage) ||
797
 
                 gimp_tool_control_handles_empty_image (active_tool->control)))
 
918
                (! gimp_image_is_empty (image) ||
 
919
                 gimp_tool_control_get_handle_empty_image (active_tool->control)))
798
920
              {
799
921
                if (gimp_tool_control_is_active (active_tool->control))
800
922
                  {
801
923
                    tool_manager_button_release_active (gimp,
802
924
                                                        &image_coords,
803
925
                                                        time, state,
804
 
                                                        gdisp);
 
926
                                                        display);
805
927
                  }
806
928
              }
807
929
 
808
930
            /*  update the tool's modifier state because it didn't get
809
931
             *  key events while BUTTON1 was down
810
932
             */
811
 
            tool_manager_focus_display_active (gimp, gdisp);
812
 
            tool_manager_modifier_state_active (gimp, state, gdisp);
 
933
            tool_manager_focus_display_active (gimp, display);
 
934
            tool_manager_modifier_state_active (gimp, state, display);
813
935
 
814
936
            tool_manager_oper_update_active (gimp,
815
937
                                             &image_coords, state,
816
 
                                             gdisp);
 
938
                                             shell->proximity,
 
939
                                             display);
817
940
 
818
941
            gtk_grab_remove (canvas);
819
942
 
820
943
            if (shell->space_release_pending)
821
 
              {
822
 
#ifdef DEBUG_MOVE_PUSH
823
 
                g_printerr ("%s: popping move tool\n", G_STRFUNC);
824
 
#endif
825
 
 
826
 
                gimp_context_set_tool (gimp_get_user_context (gimp),
827
 
                                       space_shaded_tool);
828
 
                space_shaded_tool = NULL;
829
 
 
830
 
                tool_manager_focus_display_active (gimp, gdisp);
831
 
                tool_manager_modifier_state_active (gimp, state, gdisp);
832
 
 
833
 
                tool_manager_oper_update_active (gimp,
834
 
                                                 &image_coords, state,
835
 
                                                 gdisp);
836
 
 
837
 
                shell->space_release_pending = FALSE;
838
 
 
839
 
                gdk_display_keyboard_ungrab (gdk_display, time);
840
 
              }
 
944
              gimp_display_shell_space_released (shell, state, time);
841
945
            break;
842
946
 
843
947
          case 2:
844
948
            state &= ~GDK_BUTTON2_MASK;
845
 
 
846
 
            shell->scrolling      = FALSE;
847
 
            shell->scroll_start_x = 0;
848
 
            shell->scroll_start_y = 0;
849
 
 
850
 
            gtk_grab_remove (canvas);
851
 
 
852
 
            gimp_display_shell_unset_override_cursor (shell);
 
949
            gimp_display_shell_stop_scrolling (shell);
853
950
            break;
854
951
 
855
952
          case 3:
877
974
 
878
975
        direction = sevent->direction;
879
976
 
880
 
        if (state & GDK_SHIFT_MASK)
 
977
        if (state & GDK_CONTROL_MASK)
881
978
          {
882
979
            switch (direction)
883
980
              {
884
981
              case GDK_SCROLL_UP:
885
 
                gimp_display_shell_scale (shell, GIMP_ZOOM_IN, 0.0);
 
982
                gimp_display_shell_scale_to (shell, GIMP_ZOOM_IN, 0.0,
 
983
                                             sevent->x, sevent->y);
886
984
                break;
887
985
 
888
986
              case GDK_SCROLL_DOWN:
889
 
                gimp_display_shell_scale (shell, GIMP_ZOOM_OUT, 0.0);
 
987
                gimp_display_shell_scale_to (shell, GIMP_ZOOM_OUT, 0.0,
 
988
                                             sevent->x, sevent->y);
890
989
                break;
891
990
 
892
991
              default:
898
997
            GtkAdjustment *adj = NULL;
899
998
            gdouble        value;
900
999
 
901
 
            if (state & GDK_CONTROL_MASK)
 
1000
            if (state & GDK_SHIFT_MASK)
902
1001
              switch (direction)
903
1002
                {
904
1003
                case GDK_SCROLL_UP:    direction = GDK_SCROLL_LEFT;  break;
930
1029
          }
931
1030
 
932
1031
        /*  GimpCoords passed to tools are ALWAYS in image coordinates  */
933
 
        gimp_display_shell_untransform_coords (shell,
934
 
                                               &display_coords,
935
 
                                               &image_coords);
 
1032
        gimp_display_shell_untransform_coordinate (shell,
 
1033
                                                   &display_coords,
 
1034
                                                   &image_coords);
936
1035
 
937
1036
        active_tool = tool_manager_get_active (gimp);
938
1037
 
939
1038
        if (active_tool &&
940
 
            gimp_tool_control_auto_snap_to (active_tool->control))
 
1039
            gimp_tool_control_get_snap_to (active_tool->control))
941
1040
          {
942
1041
            gint x, y, width, height;
943
1042
 
944
 
            gimp_tool_control_snap_offsets (active_tool->control,
945
 
                                            &x, &y, &width, &height);
 
1043
            gimp_tool_control_get_snap_offsets (active_tool->control,
 
1044
                                                &x, &y, &width, &height);
946
1045
 
947
1046
            if (gimp_display_shell_snap_coords (shell,
948
1047
                                                &image_coords,
949
1048
                                                &image_coords,
950
1049
                                                x, y, width, height))
951
1050
              {
952
 
                update_cursor = TRUE;
 
1051
                update_sw_cursor = TRUE;
953
1052
              }
954
1053
          }
955
1054
 
956
1055
        tool_manager_oper_update_active (gimp,
957
1056
                                         &image_coords, state,
958
 
                                         gdisp);
 
1057
                                         shell->proximity,
 
1058
                                         display);
959
1059
 
960
1060
        return_val = TRUE;
961
1061
      }
972
1072
        active_tool = tool_manager_get_active (gimp);
973
1073
 
974
1074
        if (active_tool &&
975
 
            gimp_tool_control_motion_mode (active_tool->control) ==
 
1075
            gimp_tool_control_get_motion_mode (active_tool->control) ==
976
1076
            GIMP_MOTION_MODE_COMPRESS)
977
1077
          {
978
1078
            compressed_motion = gimp_display_shell_compress_motion (shell);
989
1089
            time = gdk_event_get_time (event);
990
1090
 
991
1091
            /*  GimpCoords passed to tools are ALWAYS in image coordinates  */
992
 
            gimp_display_shell_untransform_coords (shell,
993
 
                                                   &display_coords,
994
 
                                                   &image_coords);
 
1092
            gimp_display_shell_untransform_coordinate (shell,
 
1093
                                                       &display_coords,
 
1094
                                                       &image_coords);
995
1095
 
996
1096
            if (active_tool &&
997
 
                gimp_tool_control_auto_snap_to (active_tool->control))
 
1097
                gimp_tool_control_get_snap_to (active_tool->control))
998
1098
              {
999
1099
                gint x, y, width, height;
1000
1100
 
1001
 
                gimp_tool_control_snap_offsets (active_tool->control,
1002
 
                                                &x, &y, &width, &height);
 
1101
                gimp_tool_control_get_snap_offsets (active_tool->control,
 
1102
                                                    &x, &y, &width, &height);
1003
1103
 
1004
1104
                gimp_display_shell_snap_coords (shell,
1005
1105
                                                &image_coords,
1018
1118
                                                  &display_coords);
1019
1119
          }
1020
1120
 
1021
 
        update_cursor = TRUE;
 
1121
        update_sw_cursor = TRUE;
1022
1122
 
1023
1123
        if (! shell->proximity)
1024
1124
          {
1026
1126
            gimp_display_shell_check_device_cursor (shell);
1027
1127
          }
1028
1128
 
1029
 
        if (state & GDK_BUTTON1_MASK)
 
1129
        if (shell->scrolling)
 
1130
          {
 
1131
            gimp_display_shell_scroll (shell,
 
1132
                                       (shell->scroll_start_x - mevent->x -
 
1133
                                        shell->offset_x),
 
1134
                                       (shell->scroll_start_y - mevent->y -
 
1135
                                        shell->offset_y));
 
1136
          }
 
1137
        else if (state & GDK_BUTTON1_MASK)
1030
1138
          {
1031
1139
            if (active_tool                                        &&
1032
1140
                gimp_tool_control_is_active (active_tool->control) &&
1033
 
                (! gimp_image_is_empty (gimage) ||
1034
 
                 gimp_tool_control_handles_empty_image (active_tool->control)))
 
1141
                (! gimp_image_is_empty (image) ||
 
1142
                 gimp_tool_control_get_handle_empty_image (active_tool->control)))
1035
1143
              {
1036
1144
                GdkTimeCoord **history_events;
1037
1145
                gint           n_history_events;
1043
1151
                     mevent->y < 0                 ||
1044
1152
                     mevent->x > shell->disp_width ||
1045
1153
                     mevent->y > shell->disp_height) &&
1046
 
                    ! gimp_tool_control_scroll_lock (active_tool->control))
 
1154
                    ! gimp_tool_control_get_scroll_lock (active_tool->control))
1047
1155
                  {
1048
 
                    gint off_x = 0;
1049
 
                    gint off_y = 0;
1050
 
 
1051
 
                    /*  The cases for scrolling  */
1052
 
                    if (mevent->x < 0)
1053
 
                      off_x = mevent->x;
1054
 
                    else if (mevent->x > shell->disp_width)
1055
 
                      off_x = mevent->x - shell->disp_width;
1056
 
 
1057
 
                    if (mevent->y < 0)
1058
 
                      off_y = mevent->y;
1059
 
                    else if (mevent->y > shell->disp_height)
1060
 
                      off_y = mevent->y - shell->disp_height;
1061
 
 
1062
 
                    if (gimp_display_shell_scroll (shell, off_x, off_y))
1063
 
                      {
1064
 
                        GimpCoords device_coords;
1065
 
 
1066
 
                        gimp_display_shell_get_device_coords (shell,
1067
 
                                                              mevent->device,
1068
 
                                                              &device_coords);
1069
 
 
1070
 
                        if (device_coords.x == mevent->x &&
1071
 
                            device_coords.y == mevent->y
1072
 
#ifdef G_OS_WIN32
1073
 
                            /* The Win32 backend for GDK just returns the
1074
 
                             * coordinates from the last motion/button event
1075
 
                             * for extended input devices, so if the event is
1076
 
                             * put back in the queue, this will keep scrolling
1077
 
                             * until the edge of the image is reached (bug
1078
 
                             * #167960) */
1079
 
                            && mevent->device == gdk_display_get_core_pointer (
1080
 
                              gdk_display_get_default ())
1081
 
#endif /* G_OS_WIN32 */
1082
 
                           )
1083
 
                           {
1084
 
                            /*  Put this event back on the queue
1085
 
                             *  so it keeps scrolling
1086
 
                             */
1087
 
                            gdk_event_put ((GdkEvent *) mevent);
1088
 
                          }
1089
 
                      }
 
1156
                    gimp_display_shell_autoscroll_start (shell, state, mevent);
1090
1157
                  }
1091
1158
 
1092
 
                if (gimp_tool_control_motion_mode (active_tool->control) ==
 
1159
                if (gimp_tool_control_get_motion_mode (active_tool->control) ==
1093
1160
                    GIMP_MOTION_MODE_EXACT &&
1094
1161
                    gdk_device_get_history (mevent->device, mevent->window,
1095
1162
                                            shell->last_motion_time,
1109
1176
                        /*  GimpCoords passed to tools are ALWAYS in
1110
1177
                         *  image coordinates
1111
1178
                         */
1112
 
                        gimp_display_shell_untransform_coords (shell,
1113
 
                                                               &display_coords,
1114
 
                                                               &image_coords);
 
1179
                        gimp_display_shell_untransform_coordinate (shell,
 
1180
                                                                   &display_coords,
 
1181
                                                                   &image_coords);
1115
1182
 
1116
 
                        if (gimp_tool_control_auto_snap_to (active_tool->control))
 
1183
                        if (gimp_tool_control_get_snap_to (active_tool->control))
1117
1184
                          {
1118
1185
                            gint x, y, width, height;
1119
1186
 
1120
 
                            gimp_tool_control_snap_offsets (active_tool->control,
1121
 
                                                            &x, &y, &width, &height);
 
1187
                            gimp_tool_control_get_snap_offsets (active_tool->control,
 
1188
                                                                &x, &y, &width, &height);
1122
1189
 
1123
1190
                            gimp_display_shell_snap_coords (shell,
1124
1191
                                                            &image_coords,
1130
1197
                                                    &image_coords,
1131
1198
                                                    history_events[i]->time,
1132
1199
                                                    state,
1133
 
                                                    gdisp);
 
1200
                                                    display);
1134
1201
                      }
1135
1202
 
1136
1203
                    gdk_device_free_history (history_events, n_history_events);
1139
1206
                  {
1140
1207
                    tool_manager_motion_active (gimp,
1141
1208
                                                &image_coords, time, state,
1142
 
                                                gdisp);
 
1209
                                                display);
1143
1210
                  }
1144
1211
 
1145
1212
                shell->last_motion_time = mevent->time;
1146
1213
              }
1147
1214
          }
1148
 
        else if (state & GDK_BUTTON2_MASK)
1149
 
          {
1150
 
            if (shell->scrolling)
1151
 
              {
1152
 
                gimp_display_shell_scroll (shell,
1153
 
                                           (shell->scroll_start_x - mevent->x -
1154
 
                                            shell->offset_x),
1155
 
                                           (shell->scroll_start_y - mevent->y -
1156
 
                                            shell->offset_y));
1157
 
              }
1158
 
          }
1159
1215
 
1160
1216
        if (! (state &
1161
1217
               (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)))
1162
1218
          {
1163
1219
            tool_manager_oper_update_active (gimp,
1164
1220
                                             &image_coords, state,
1165
 
                                             gdisp);
 
1221
                                             shell->proximity,
 
1222
                                             display);
1166
1223
          }
1167
1224
      }
1168
1225
      break;
1169
1226
 
1170
1227
    case GDK_KEY_PRESS:
1171
 
      {
1172
 
        GdkEventKey *kevent = (GdkEventKey *) event;
1173
 
 
1174
 
        tool_manager_focus_display_active (gimp, gdisp);
1175
 
 
1176
 
        switch (kevent->keyval)
1177
 
          {
1178
 
          case GDK_Return:
1179
 
          case GDK_KP_Enter:
1180
 
          case GDK_BackSpace:
1181
 
          case GDK_Delete:
1182
 
          case GDK_Escape:
1183
 
          case GDK_Left:
1184
 
          case GDK_Right:
1185
 
          case GDK_Up:
1186
 
          case GDK_Down:
1187
 
            if (gimp_image_is_empty (gimage) ||
1188
 
                ! tool_manager_key_press_active (gimp,
1189
 
                                                 kevent,
1190
 
                                                 gdisp))
 
1228
      if (state & GDK_BUTTON1_MASK)
 
1229
        {
 
1230
          GdkEventKey *kevent = (GdkEventKey *) event;
 
1231
 
 
1232
          switch (kevent->keyval)
 
1233
            {
 
1234
            case GDK_Alt_L:     case GDK_Alt_R:
 
1235
            case GDK_Shift_L:   case GDK_Shift_R:
 
1236
            case GDK_Control_L: case GDK_Control_R:
1191
1237
              {
1192
 
                GimpController *keyboard;
1193
 
 
1194
 
                keyboard = gimp_controllers_get_keyboard (gimp);
1195
 
 
1196
 
                if (keyboard)
1197
 
                  gimp_controller_keyboard_key_press (GIMP_CONTROLLER_KEYBOARD (keyboard),
1198
 
                                                      kevent);
 
1238
                GdkModifierType key;
 
1239
 
 
1240
                key = gimp_display_shell_key_to_state (kevent->keyval);
 
1241
                state |= key;
 
1242
 
 
1243
                if (active_tool                                        &&
 
1244
                    gimp_tool_control_is_active (active_tool->control) &&
 
1245
                    ! gimp_image_is_empty (image))
 
1246
                  {
 
1247
                    tool_manager_active_modifier_state_active (gimp, state,
 
1248
                                                               display);
 
1249
                  }
1199
1250
              }
1200
 
 
1201
 
            return_val = TRUE;
1202
 
            break;
1203
 
 
1204
 
          case GDK_space:
 
1251
              break;
 
1252
            }
 
1253
        }
 
1254
      else
 
1255
        {
 
1256
          GdkEventKey *kevent = (GdkEventKey *) event;
 
1257
 
 
1258
          tool_manager_focus_display_active (gimp, display);
 
1259
 
 
1260
          switch (kevent->keyval)
1205
1261
            {
1206
 
              active_tool = tool_manager_get_active (gimp);
1207
 
 
1208
 
              if (active_tool &&
1209
 
                  ! shell->space_pressed && ! GIMP_IS_MOVE_TOOL (active_tool))
1210
 
                {
1211
 
                  GimpToolInfo *move_tool_info;
1212
 
 
1213
 
                  move_tool_info = (GimpToolInfo *)
1214
 
                    gimp_container_get_child_by_name (gimp->tool_info_list,
1215
 
                                                      "gimp-move-tool");
1216
 
 
1217
 
                  if (GIMP_IS_TOOL_INFO (move_tool_info))
 
1262
            case GDK_Return:
 
1263
            case GDK_KP_Enter:
 
1264
            case GDK_BackSpace:
 
1265
            case GDK_Delete:
 
1266
            case GDK_Escape:
 
1267
            case GDK_Left:
 
1268
            case GDK_Right:
 
1269
            case GDK_Up:
 
1270
            case GDK_Down:
 
1271
              if (gimp_image_is_empty (image) ||
 
1272
                  ! tool_manager_key_press_active (gimp,
 
1273
                                                   kevent,
 
1274
                                                   display))
 
1275
                {
 
1276
                  GimpController *keyboard = gimp_controllers_get_keyboard (gimp);
 
1277
 
 
1278
                  if (keyboard)
 
1279
                    gimp_controller_keyboard_key_press (GIMP_CONTROLLER_KEYBOARD (keyboard),
 
1280
                                                        kevent);
 
1281
                }
 
1282
 
 
1283
              return_val = TRUE;
 
1284
              break;
 
1285
 
 
1286
            case GDK_space:
 
1287
              gimp_display_shell_space_pressed (shell, state, time);
 
1288
              return_val = TRUE;
 
1289
              break;
 
1290
 
 
1291
            case GDK_Tab:
 
1292
            case GDK_ISO_Left_Tab:
 
1293
              if (state & GDK_CONTROL_MASK)
 
1294
                {
 
1295
                  if (! gimp_image_is_empty (image))
1218
1296
                    {
1219
 
#ifdef DEBUG_MOVE_PUSH
1220
 
                      g_printerr ("%s: pushing move tool\n", G_STRFUNC);
1221
 
#endif
1222
 
 
1223
 
                      space_shaded_tool = active_tool->tool_info;
1224
 
 
1225
 
                      gdk_keyboard_grab (canvas->window, FALSE, time);
1226
 
 
1227
 
                      gimp_context_set_tool (gimp_get_user_context (gimp),
1228
 
                                             move_tool_info);
1229
 
 
1230
 
                      tool_manager_focus_display_active (gimp, gdisp);
1231
 
                      tool_manager_modifier_state_active (gimp, state, gdisp);
1232
 
 
1233
 
                      shell->space_pressed = TRUE;
 
1297
                      if (kevent->keyval == GDK_Tab)
 
1298
                        gimp_display_shell_layer_select_init (shell,
 
1299
                                                              1, kevent->time);
 
1300
                      else
 
1301
                        gimp_display_shell_layer_select_init (shell,
 
1302
                                                              -1, kevent->time);
1234
1303
                    }
1235
1304
                }
 
1305
              else
 
1306
                {
 
1307
                  gimp_dialog_factories_toggle ();
 
1308
                }
 
1309
 
 
1310
              return_val = TRUE;
 
1311
              break;
 
1312
 
 
1313
              /*  Update the state based on modifiers being pressed  */
 
1314
            case GDK_Alt_L:     case GDK_Alt_R:
 
1315
            case GDK_Shift_L:   case GDK_Shift_R:
 
1316
            case GDK_Control_L: case GDK_Control_R:
 
1317
              {
 
1318
                GdkModifierType key;
 
1319
 
 
1320
                key = gimp_display_shell_key_to_state (kevent->keyval);
 
1321
                state |= key;
 
1322
 
 
1323
                if (! gimp_image_is_empty (image))
 
1324
                  tool_manager_modifier_state_active (gimp, state, display);
 
1325
              }
 
1326
 
 
1327
              break;
1236
1328
            }
1237
1329
 
1238
 
            return_val = TRUE;
1239
 
            break;
1240
 
 
1241
 
          case GDK_Tab:
1242
 
          case GDK_ISO_Left_Tab:
1243
 
            if (state & GDK_CONTROL_MASK)
 
1330
          tool_manager_oper_update_active (gimp,
 
1331
                                           &image_coords, state,
 
1332
                                           shell->proximity,
 
1333
                                           display);
 
1334
        }
 
1335
      break;
 
1336
 
 
1337
    case GDK_KEY_RELEASE:
 
1338
      if (state & GDK_BUTTON1_MASK)
 
1339
        {
 
1340
          GdkEventKey *kevent = (GdkEventKey *) event;
 
1341
 
 
1342
          switch (kevent->keyval)
 
1343
            {
 
1344
            case GDK_Alt_L:     case GDK_Alt_R:
 
1345
            case GDK_Shift_L:   case GDK_Shift_R:
 
1346
            case GDK_Control_L: case GDK_Control_R:
1244
1347
              {
1245
 
                if (! gimp_image_is_empty (gimage))
 
1348
                GdkModifierType key;
 
1349
 
 
1350
                key = gimp_display_shell_key_to_state (kevent->keyval);
 
1351
                state &= ~key;
 
1352
 
 
1353
                if (active_tool                                        &&
 
1354
                    gimp_tool_control_is_active (active_tool->control) &&
 
1355
                    ! gimp_image_is_empty (image))
1246
1356
                  {
1247
 
                    if (kevent->keyval == GDK_Tab)
1248
 
                      gimp_display_shell_layer_select_init (shell,
1249
 
                                                            1, kevent->time);
1250
 
                    else
1251
 
                      gimp_display_shell_layer_select_init (shell,
1252
 
                                                            -1, kevent->time);
 
1357
                    tool_manager_active_modifier_state_active (gimp, state,
 
1358
                                                               display);
1253
1359
                  }
1254
1360
              }
1255
 
            else
 
1361
              break;
 
1362
            }
 
1363
        }
 
1364
      else
 
1365
        {
 
1366
          GdkEventKey *kevent = (GdkEventKey *) event;
 
1367
 
 
1368
          tool_manager_focus_display_active (gimp, display);
 
1369
 
 
1370
          switch (kevent->keyval)
 
1371
            {
 
1372
            case GDK_space:
 
1373
              gimp_display_shell_space_released (shell, state, time);
 
1374
              return_val = TRUE;
 
1375
              break;
 
1376
 
 
1377
              /*  Update the state based on modifiers being pressed  */
 
1378
            case GDK_Alt_L:     case GDK_Alt_R:
 
1379
            case GDK_Shift_L:   case GDK_Shift_R:
 
1380
            case GDK_Control_L: case GDK_Control_R:
1256
1381
              {
1257
 
                GimpDialogFactory *dialog_factory;
1258
 
 
1259
 
                dialog_factory = gimp_dialog_factory_from_name ("toolbox");
1260
 
 
1261
 
                /*  Hide or show all dialogs  */
1262
 
                gimp_dialog_factories_toggle (dialog_factory, FALSE);
 
1382
                GdkModifierType key;
 
1383
 
 
1384
                key = gimp_display_shell_key_to_state (kevent->keyval);
 
1385
                state &= ~key;
 
1386
 
 
1387
                /*  For all modifier keys: call the tools modifier_state *and*
 
1388
                 *  oper_update method so tools can choose if they are interested
 
1389
                 *  in the press itself or only in the resulting state
 
1390
                 */
 
1391
                if (! gimp_image_is_empty (image))
 
1392
                  tool_manager_modifier_state_active (gimp, state, display);
1263
1393
              }
1264
1394
 
1265
 
            return_val = TRUE;
1266
 
            break;
1267
 
 
1268
 
            /*  Update the state based on modifiers being pressed  */
1269
 
          case GDK_Alt_L:     case GDK_Alt_R:
1270
 
          case GDK_Shift_L:   case GDK_Shift_R:
1271
 
          case GDK_Control_L: case GDK_Control_R:
1272
 
            {
1273
 
              GdkModifierType key;
1274
 
 
1275
 
              key = gimp_display_shell_key_to_state (kevent->keyval);
1276
 
              state |= key;
1277
 
 
1278
 
              /*  For all modifier keys: call the tools modifier_state *and*
1279
 
               *  oper_update method so tools can choose if they are interested
1280
 
               *  in the release itself or only in the resulting state
1281
 
               */
1282
 
              if (! gimp_image_is_empty (gimage))
1283
 
                tool_manager_modifier_state_active (gimp, state, gdisp);
1284
 
            }
1285
 
 
1286
 
            break;
1287
 
          }
1288
 
 
1289
 
        tool_manager_oper_update_active (gimp,
1290
 
                                         &image_coords, state,
1291
 
                                         gdisp);
1292
 
      }
1293
 
      break;
1294
 
 
1295
 
    case GDK_KEY_RELEASE:
1296
 
      {
1297
 
        GdkEventKey *kevent = (GdkEventKey *) event;
1298
 
 
1299
 
        tool_manager_focus_display_active (gimp, gdisp);
1300
 
 
1301
 
        switch (kevent->keyval)
1302
 
          {
1303
 
          case GDK_space:
1304
 
            if (shell->space_pressed)
1305
 
              {
1306
 
#ifdef DEBUG_MOVE_PUSH
1307
 
                g_printerr ("%s: popping move tool\n", G_STRFUNC);
1308
 
#endif
1309
 
 
1310
 
                gimp_context_set_tool (gimp_get_user_context (gimp),
1311
 
                                       space_shaded_tool);
1312
 
                space_shaded_tool = NULL;
1313
 
 
1314
 
                tool_manager_focus_display_active (gimp, gdisp);
1315
 
                tool_manager_modifier_state_active (gimp, state, gdisp);
1316
 
 
1317
 
                shell->space_pressed = FALSE;
1318
 
 
1319
 
                gdk_display_keyboard_ungrab (gdk_display, time);
1320
 
             }
1321
 
 
1322
 
            return_val = TRUE;
1323
 
            break;
1324
 
 
1325
 
            /*  Update the state based on modifiers being pressed  */
1326
 
          case GDK_Alt_L:     case GDK_Alt_R:
1327
 
          case GDK_Shift_L:   case GDK_Shift_R:
1328
 
          case GDK_Control_L: case GDK_Control_R:
1329
 
            {
1330
 
              GdkModifierType key;
1331
 
 
1332
 
              key = gimp_display_shell_key_to_state (kevent->keyval);
1333
 
              state &= ~key;
1334
 
 
1335
 
              /*  For all modifier keys: call the tools modifier_state *and*
1336
 
               *  oper_update method so tools can choose if they are interested
1337
 
               *  in the press itself or only in the resulting state
1338
 
               */
1339
 
              if (! gimp_image_is_empty (gimage))
1340
 
                tool_manager_modifier_state_active (gimp, state, gdisp);
1341
 
            }
1342
 
 
1343
 
            break;
1344
 
          }
1345
 
 
1346
 
        tool_manager_oper_update_active (gimp,
1347
 
                                         &image_coords, state,
1348
 
                                         gdisp);
1349
 
      }
 
1395
              break;
 
1396
            }
 
1397
 
 
1398
          tool_manager_oper_update_active (gimp,
 
1399
                                           &image_coords, state,
 
1400
                                           shell->proximity,
 
1401
                                           display);
 
1402
        }
1350
1403
      break;
1351
1404
 
1352
1405
    default:
1365
1418
 
1366
1419
      if (active_tool)
1367
1420
        {
1368
 
          if ((! gimp_image_is_empty (gimage) ||
1369
 
               gimp_tool_control_handles_empty_image (active_tool->control)) &&
 
1421
          if ((! gimp_image_is_empty (image) ||
 
1422
               gimp_tool_control_get_handle_empty_image (active_tool->control)) &&
1370
1423
              ! (state & (GDK_BUTTON1_MASK |
1371
1424
                          GDK_BUTTON2_MASK |
1372
1425
                          GDK_BUTTON3_MASK)))
1373
1426
            {
1374
1427
              tool_manager_cursor_update_active (gimp,
1375
1428
                                                 &image_coords, state,
1376
 
                                                 gdisp);
 
1429
                                                 display);
1377
1430
            }
1378
 
          else if (gimp_image_is_empty (gimage))
 
1431
          else if (gimp_image_is_empty (image) &&
 
1432
                   ! gimp_tool_control_get_handle_empty_image (active_tool->control))
1379
1433
            {
1380
1434
              gimp_display_shell_set_cursor (shell,
1381
 
                                             GIMP_CURSOR_BAD,
 
1435
                                             GIMP_CURSOR_MOUSE,
1382
1436
                                             gimp_tool_control_get_tool_cursor (active_tool->control),
1383
 
                                             GIMP_CURSOR_MODIFIER_NONE);
 
1437
                                             GIMP_CURSOR_MODIFIER_BAD);
1384
1438
            }
1385
1439
        }
1386
1440
      else
1387
1441
        {
1388
1442
          gimp_display_shell_set_cursor (shell,
1389
 
                                         GIMP_CURSOR_BAD,
 
1443
                                         GIMP_CURSOR_MOUSE,
1390
1444
                                         GIMP_TOOL_CURSOR_NONE,
1391
 
                                         GIMP_CURSOR_MODIFIER_NONE);
 
1445
                                         GIMP_CURSOR_MODIFIER_BAD);
1392
1446
        }
1393
1447
    }
1394
1448
 
1395
 
  if (update_cursor)
 
1449
  if (update_sw_cursor)
1396
1450
    gimp_display_shell_update_cursor (shell,
1397
1451
                                      (gint) display_coords.x,
1398
1452
                                      (gint) display_coords.y,
1402
1456
  return return_val;
1403
1457
}
1404
1458
 
 
1459
static gboolean
 
1460
gimp_display_shell_ruler_button_press (GtkWidget        *widget,
 
1461
                                       GdkEventButton   *event,
 
1462
                                       GimpDisplayShell *shell,
 
1463
                                       gboolean          horizontal)
 
1464
{
 
1465
  GimpDisplay *display = shell->display;
 
1466
 
 
1467
  if (display->image->gimp->busy)
 
1468
    return TRUE;
 
1469
 
 
1470
  if (event->type == GDK_BUTTON_PRESS && event->button == 1)
 
1471
    {
 
1472
      GimpTool *active_tool;
 
1473
      gboolean  sample_point;
 
1474
 
 
1475
      active_tool  = tool_manager_get_active (display->image->gimp);
 
1476
      sample_point = (event->state & GDK_CONTROL_MASK);
 
1477
 
 
1478
      if (! ((sample_point && (GIMP_IS_COLOR_TOOL (active_tool) &&
 
1479
                               ! (GIMP_IS_PAINT_TOOL (active_tool) &&
 
1480
                                  ! GIMP_PAINT_TOOL (active_tool)->pick_colors)))
 
1481
 
 
1482
             ||
 
1483
 
 
1484
             (! sample_point && GIMP_IS_MOVE_TOOL (active_tool))))
 
1485
        {
 
1486
          GimpToolInfo *tool_info;
 
1487
 
 
1488
          tool_info = gimp_get_tool_info (display->image->gimp,
 
1489
                                          sample_point ?
 
1490
                                          "gimp-color-picker-tool" :
 
1491
                                          "gimp-move-tool");
 
1492
 
 
1493
          if (tool_info)
 
1494
            gimp_context_set_tool (gimp_get_user_context (display->image->gimp),
 
1495
                                   tool_info);
 
1496
        }
 
1497
 
 
1498
      active_tool = tool_manager_get_active (display->image->gimp);
 
1499
 
 
1500
      if (active_tool)
 
1501
        {
 
1502
          gdk_pointer_grab (shell->canvas->window, FALSE,
 
1503
                            GDK_POINTER_MOTION_HINT_MASK |
 
1504
                            GDK_BUTTON1_MOTION_MASK |
 
1505
                            GDK_BUTTON_RELEASE_MASK,
 
1506
                            NULL, NULL, event->time);
 
1507
 
 
1508
          gdk_keyboard_grab (shell->canvas->window, FALSE, event->time);
 
1509
 
 
1510
          if (sample_point)
 
1511
            gimp_color_tool_start_sample_point (active_tool, display);
 
1512
          else if (horizontal)
 
1513
            gimp_move_tool_start_hguide (active_tool, display);
 
1514
          else
 
1515
            gimp_move_tool_start_vguide (active_tool, display);
 
1516
        }
 
1517
    }
 
1518
 
 
1519
  return FALSE;
 
1520
}
 
1521
 
1405
1522
gboolean
1406
1523
gimp_display_shell_hruler_button_press (GtkWidget        *widget,
1407
1524
                                        GdkEventButton   *event,
1408
1525
                                        GimpDisplayShell *shell)
1409
1526
{
1410
 
  GimpDisplay *gdisp = shell->gdisp;
1411
 
 
1412
 
  if (gdisp->gimage->gimp->busy)
1413
 
    return TRUE;
1414
 
 
1415
 
  if (event->type == GDK_BUTTON_PRESS && event->button == 1)
1416
 
    {
1417
 
      GimpToolInfo *tool_info;
1418
 
 
1419
 
      tool_info = (GimpToolInfo *)
1420
 
        gimp_container_get_child_by_name (gdisp->gimage->gimp->tool_info_list,
1421
 
                                          "gimp-move-tool");
1422
 
 
1423
 
      if (tool_info)
1424
 
        {
1425
 
          GimpTool *active_tool;
1426
 
 
1427
 
          gimp_context_set_tool (gimp_get_user_context (gdisp->gimage->gimp),
1428
 
                                 tool_info);
1429
 
 
1430
 
          active_tool = tool_manager_get_active (gdisp->gimage->gimp);
1431
 
 
1432
 
          if (active_tool)
1433
 
            {
1434
 
              gdk_pointer_grab (shell->canvas->window, FALSE,
1435
 
                                GDK_POINTER_MOTION_HINT_MASK |
1436
 
                                GDK_BUTTON1_MOTION_MASK |
1437
 
                                GDK_BUTTON_RELEASE_MASK,
1438
 
                                NULL, NULL, event->time);
1439
 
 
1440
 
              gdk_keyboard_grab (shell->canvas->window, FALSE, event->time);
1441
 
 
1442
 
              gimp_move_tool_start_hguide (active_tool, gdisp);
1443
 
            }
1444
 
        }
1445
 
    }
1446
 
 
1447
 
  return FALSE;
 
1527
  return gimp_display_shell_ruler_button_press (widget, event, shell, TRUE);
1448
1528
}
1449
1529
 
1450
1530
gboolean
1452
1532
                                        GdkEventButton   *event,
1453
1533
                                        GimpDisplayShell *shell)
1454
1534
{
1455
 
  GimpDisplay *gdisp = shell->gdisp;
1456
 
 
1457
 
  if (gdisp->gimage->gimp->busy)
1458
 
    return TRUE;
1459
 
 
1460
 
  if (event->type == GDK_BUTTON_PRESS && event->button == 1)
1461
 
    {
1462
 
      GimpToolInfo *tool_info;
1463
 
 
1464
 
      tool_info = (GimpToolInfo *)
1465
 
        gimp_container_get_child_by_name (gdisp->gimage->gimp->tool_info_list,
1466
 
                                          "gimp-move-tool");
1467
 
 
1468
 
      if (tool_info)
1469
 
        {
1470
 
          GimpTool *active_tool;
1471
 
 
1472
 
          gimp_context_set_tool (gimp_get_user_context (gdisp->gimage->gimp),
1473
 
                                 tool_info);
1474
 
 
1475
 
          active_tool = tool_manager_get_active (gdisp->gimage->gimp);
1476
 
 
1477
 
          if (active_tool)
1478
 
            {
1479
 
              gdk_pointer_grab (shell->canvas->window, FALSE,
1480
 
                                GDK_POINTER_MOTION_HINT_MASK |
1481
 
                                GDK_BUTTON1_MOTION_MASK |
1482
 
                                GDK_BUTTON_RELEASE_MASK,
1483
 
                                NULL, NULL, event->time);
1484
 
 
1485
 
              gdk_keyboard_grab (shell->canvas->window, FALSE, event->time);
1486
 
 
1487
 
              gimp_move_tool_start_vguide (active_tool, gdisp);
1488
 
            }
1489
 
        }
1490
 
    }
1491
 
 
1492
 
  return FALSE;
 
1535
  return gimp_display_shell_ruler_button_press (widget, event, shell, FALSE);
1493
1536
}
1494
1537
 
1495
1538
gboolean
1497
1540
                                        GdkEventButton   *event,
1498
1541
                                        GimpDisplayShell *shell)
1499
1542
{
1500
 
  if (! shell->gdisp->gimage->gimp->busy)
 
1543
  if (! shell->display->image->gimp->busy)
1501
1544
    {
1502
1545
      if (event->button == 1)
1503
1546
        {
1514
1557
}
1515
1558
 
1516
1559
gboolean
1517
 
gimp_display_shell_qmask_button_press (GtkWidget        *widget,
1518
 
                                       GdkEventButton   *bevent,
1519
 
                                       GimpDisplayShell *shell)
 
1560
gimp_display_shell_quick_mask_button_press (GtkWidget        *widget,
 
1561
                                            GdkEventButton   *bevent,
 
1562
                                            GimpDisplayShell *shell)
1520
1563
{
1521
1564
  if ((bevent->type == GDK_BUTTON_PRESS) && (bevent->button == 3))
1522
1565
    {
1523
 
      gimp_ui_manager_ui_popup (shell->menubar_manager, "/qmask-popup",
 
1566
      gimp_ui_manager_ui_popup (shell->menubar_manager, "/quick-mask-popup",
1524
1567
                                GTK_WIDGET (shell),
1525
1568
                                NULL, NULL, NULL, NULL);
1526
1569
 
1531
1574
}
1532
1575
 
1533
1576
void
1534
 
gimp_display_shell_qmask_toggled (GtkWidget        *widget,
1535
 
                                  GimpDisplayShell *shell)
 
1577
gimp_display_shell_quick_mask_toggled (GtkWidget        *widget,
 
1578
                                       GimpDisplayShell *shell)
1536
1579
{
1537
1580
  if (GTK_TOGGLE_BUTTON (widget)->active !=
1538
 
      gimp_image_get_qmask_state (shell->gdisp->gimage))
 
1581
      gimp_image_get_quick_mask_state (shell->display->image))
1539
1582
    {
1540
 
      gimp_image_set_qmask_state (shell->gdisp->gimage,
1541
 
                                  GTK_TOGGLE_BUTTON (widget)->active);
 
1583
      gimp_image_set_quick_mask_state (shell->display->image,
 
1584
                                       GTK_TOGGLE_BUTTON (widget)->active);
1542
1585
 
1543
 
      gimp_image_flush (shell->gdisp->gimage);
 
1586
      gimp_image_flush (shell->display->image);
1544
1587
    }
1545
1588
}
1546
1589
 
1574
1617
  gimp_display_shell_scroll (shell, (adjustment->value - shell->offset_x), 0);
1575
1618
}
1576
1619
 
1577
 
static gboolean
1578
 
gimp_display_shell_get_event_coords (GimpDisplayShell *shell,
1579
 
                                     GdkEvent         *event,
1580
 
                                     GdkDevice        *device,
1581
 
                                     GimpCoords       *coords)
1582
 
{
1583
 
  if (gdk_event_get_axis (event, GDK_AXIS_X, &coords->x))
1584
 
    {
1585
 
      gdk_event_get_axis (event, GDK_AXIS_Y, &coords->y);
1586
 
 
1587
 
      /*  CLAMP() the return value of each *_get_axis() call to be safe
1588
 
       *  against buggy XInput drivers. Provide default values if the
1589
 
       *  requested axis does not exist.
1590
 
       */
1591
 
 
1592
 
      if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &coords->pressure))
1593
 
        coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
1594
 
                                  GIMP_COORDS_MAX_PRESSURE);
1595
 
      else
1596
 
        coords->pressure = GIMP_COORDS_DEFAULT_PRESSURE;
1597
 
 
1598
 
      if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &coords->xtilt))
1599
 
        coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
1600
 
                               GIMP_COORDS_MAX_TILT);
1601
 
      else
1602
 
        coords->xtilt = GIMP_COORDS_DEFAULT_TILT;
1603
 
 
1604
 
      if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &coords->ytilt))
1605
 
        coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
1606
 
                               GIMP_COORDS_MAX_TILT);
1607
 
      else
1608
 
        coords->ytilt = GIMP_COORDS_DEFAULT_TILT;
1609
 
 
1610
 
      if (gdk_event_get_axis (event, GDK_AXIS_WHEEL, &coords->wheel))
1611
 
        coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
1612
 
                               GIMP_COORDS_MAX_WHEEL);
1613
 
      else
1614
 
        coords->wheel = GIMP_COORDS_DEFAULT_WHEEL;
1615
 
 
1616
 
      return TRUE;
1617
 
    }
1618
 
 
1619
 
  gimp_display_shell_get_device_coords (shell, device, coords);
1620
 
 
1621
 
  return FALSE;
1622
 
}
1623
 
 
1624
 
static void
1625
 
gimp_display_shell_get_device_coords (GimpDisplayShell *shell,
1626
 
                                      GdkDevice        *device,
1627
 
                                      GimpCoords       *coords)
1628
 
{
1629
 
  gdouble axes[GDK_AXIS_LAST];
1630
 
 
1631
 
  gdk_device_get_state (device, shell->canvas->window, axes, NULL);
1632
 
 
1633
 
  gdk_device_get_axis (device, axes, GDK_AXIS_X, &coords->x);
1634
 
  gdk_device_get_axis (device, axes, GDK_AXIS_Y, &coords->y);
1635
 
 
1636
 
  /*  CLAMP() the return value of each *_get_axis() call to be safe
1637
 
   *  against buggy XInput drivers. Provide default values if the
1638
 
   *  requested axis does not exist.
1639
 
   */
1640
 
 
1641
 
  if (gdk_device_get_axis (device, axes, GDK_AXIS_PRESSURE, &coords->pressure))
1642
 
    coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
1643
 
                              GIMP_COORDS_MAX_PRESSURE);
1644
 
  else
1645
 
    coords->pressure = GIMP_COORDS_DEFAULT_PRESSURE;
1646
 
 
1647
 
  if (gdk_device_get_axis (device, axes, GDK_AXIS_XTILT, &coords->xtilt))
1648
 
    coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
1649
 
                           GIMP_COORDS_MAX_TILT);
1650
 
  else
1651
 
    coords->xtilt = GIMP_COORDS_DEFAULT_TILT;
1652
 
 
1653
 
  if (gdk_device_get_axis (device, axes, GDK_AXIS_YTILT, &coords->ytilt))
1654
 
    coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
1655
 
                           GIMP_COORDS_MAX_TILT);
1656
 
  else
1657
 
    coords->ytilt = GIMP_COORDS_DEFAULT_TILT;
1658
 
 
1659
 
  if (gdk_device_get_axis (device, axes, GDK_AXIS_WHEEL, &coords->wheel))
1660
 
    coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
1661
 
                           GIMP_COORDS_MAX_WHEEL);
1662
 
  else
1663
 
    coords->wheel = GIMP_COORDS_DEFAULT_WHEEL;
1664
 
}
1665
 
 
1666
 
static void
1667
 
gimp_display_shell_get_time_coords (GimpDisplayShell *shell,
1668
 
                                    GdkDevice        *device,
1669
 
                                    GdkTimeCoord     *event,
1670
 
                                    GimpCoords       *coords)
1671
 
{
1672
 
  gdk_device_get_axis (device, event->axes, GDK_AXIS_X, &coords->x);
1673
 
  gdk_device_get_axis (device, event->axes, GDK_AXIS_Y, &coords->y);
1674
 
 
1675
 
  /*  CLAMP() the return value of each *_get_axis() call to be safe
1676
 
   *  against buggy XInput drivers. Provide default values if the
1677
 
   *  requested axis does not exist.
1678
 
   */
1679
 
 
1680
 
  if (gdk_device_get_axis (device, event->axes, GDK_AXIS_PRESSURE, &coords->pressure))
1681
 
    coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
1682
 
                              GIMP_COORDS_MAX_PRESSURE);
1683
 
  else
1684
 
    coords->pressure = GIMP_COORDS_DEFAULT_PRESSURE;
1685
 
 
1686
 
  if (gdk_device_get_axis (device, event->axes, GDK_AXIS_XTILT, &coords->xtilt))
1687
 
    coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
1688
 
                           GIMP_COORDS_MAX_TILT);
1689
 
  else
1690
 
    coords->xtilt = GIMP_COORDS_DEFAULT_TILT;
1691
 
 
1692
 
  if (gdk_device_get_axis (device, event->axes, GDK_AXIS_YTILT, &coords->ytilt))
1693
 
    coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
1694
 
                           GIMP_COORDS_MAX_TILT);
1695
 
  else
1696
 
    coords->ytilt = GIMP_COORDS_DEFAULT_TILT;
1697
 
 
1698
 
  if (gdk_device_get_axis (device, event->axes, GDK_AXIS_WHEEL, &coords->wheel))
1699
 
    coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
1700
 
                           GIMP_COORDS_MAX_WHEEL);
1701
 
  else
1702
 
    coords->wheel = GIMP_COORDS_DEFAULT_WHEEL;
1703
 
}
1704
 
 
1705
 
static gboolean
1706
 
gimp_display_shell_get_event_state (GimpDisplayShell *shell,
1707
 
                                    GdkEvent         *event,
1708
 
                                    GdkDevice        *device,
1709
 
                                    GdkModifierType  *state)
1710
 
{
1711
 
  if (gdk_event_get_state (event, state))
1712
 
    return TRUE;
1713
 
 
1714
 
  gimp_display_shell_get_device_state (shell, device, state);
1715
 
 
1716
 
  return FALSE;
1717
 
}
1718
 
 
1719
 
static void
1720
 
gimp_display_shell_get_device_state (GimpDisplayShell *shell,
1721
 
                                     GdkDevice        *device,
1722
 
                                     GdkModifierType  *state)
1723
 
{
1724
 
  gdk_device_get_state (device, shell->canvas->window, NULL, state);
1725
 
}
1726
 
 
1727
1620
static GdkModifierType
1728
1621
gimp_display_shell_key_to_state (gint key)
1729
1622
{
1756
1649
static GdkEvent *
1757
1650
gimp_display_shell_compress_motion (GimpDisplayShell *shell)
1758
1651
{
1759
 
  GdkEvent *event;
1760
1652
  GList    *requeued_events = NULL;
1761
1653
  GList    *list;
1762
1654
  GdkEvent *last_motion = NULL;
1766
1658
   */
1767
1659
  while (gdk_events_pending ())
1768
1660
    {
1769
 
      event = gdk_event_get ();
 
1661
      GdkEvent *event = gdk_event_get ();
1770
1662
 
1771
1663
      if (!event)
1772
 
        {
1773
 
          /* Do nothing */
1774
 
        }
 
1664
        {
 
1665
          /* Do nothing */
 
1666
        }
1775
1667
      else if ((gtk_get_event_widget (event) == shell->canvas) &&
1776
 
               (event->any.type == GDK_MOTION_NOTIFY))
1777
 
        {
 
1668
               (event->any.type == GDK_MOTION_NOTIFY))
 
1669
        {
1778
1670
          if (last_motion)
1779
1671
            gdk_event_free (last_motion);
1780
1672
 
1781
 
          last_motion = event;
1782
 
        }
 
1673
          last_motion = event;
 
1674
        }
1783
1675
      else
1784
 
        {
1785
 
          requeued_events = g_list_prepend (requeued_events, event);
1786
 
        }
 
1676
        {
 
1677
          requeued_events = g_list_prepend (requeued_events, event);
 
1678
        }
1787
1679
    }
1788
1680
 
1789
1681
  /* Replay the remains of our private event list back into the
1793
1685
 
1794
1686
  for (list = requeued_events; list; list = g_list_next (list))
1795
1687
    {
1796
 
      gdk_event_put ((GdkEvent *) list->data);
1797
 
      gdk_event_free ((GdkEvent *) list->data);
 
1688
      GdkEvent *event = list->data;
 
1689
 
 
1690
      gdk_event_put (event);
 
1691
      gdk_event_free (event);
1798
1692
    }
1799
1693
 
1800
1694
  g_list_free (requeued_events);