summaryrefslogtreecommitdiffstats
path: root/src/ui/tool/modifier-tracker.cpp
blob: 70c85a6a5130965f4d2486b66b0b9acb67e14b78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * Fine-grained modifier tracker for event handling.
 */
/* Authors:
 *   Krzysztof Kosiński <tweenk.pl@gmail.com>
 *
 * Copyright (C) 2009 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include "ui/tool/event-utils.h"
#include "ui/tool/modifier-tracker.h"

namespace Inkscape {
namespace UI {

ModifierTracker::ModifierTracker()
    : _left_shift(false)
    , _right_shift(false)
    , _left_ctrl(false)
    , _right_ctrl(false)
    , _left_alt(false)
    , _right_alt(false)
{}

bool ModifierTracker::event(GdkEvent *event)
{
    switch (event->type) {
    case GDK_KEY_PRESS:
        switch (shortcut_key(event->key)) {
        case GDK_KEY_Shift_L:
            _left_shift = true;
            break;
        case GDK_KEY_Shift_R:
            _right_shift = true;
            break;
        case GDK_KEY_Control_L:
            _left_ctrl = true;
            break;
        case GDK_KEY_Control_R:
            _right_ctrl = true;
            break;
        case GDK_KEY_Alt_L:
            _left_alt = true;
            break;
        case GDK_KEY_Alt_R:
            _right_alt = true;
            break;
        }
        break;
    case GDK_KEY_RELEASE:
        switch (shortcut_key(event->key)) {
        case GDK_KEY_Shift_L:
            _left_shift = false;
            break;
        case GDK_KEY_Shift_R:
            _right_shift = false;
            break;
        case GDK_KEY_Control_L:
            _left_ctrl = false;
            break;
        case GDK_KEY_Control_R:
            _right_ctrl = false;
            break;
        case GDK_KEY_Alt_L:
            _left_alt = false;
            break;
        case GDK_KEY_Alt_R:
            _right_alt = false;
            break;
        }
        break;
    default: break;
    }

    return false;
}

} // namespace UI
} // namespace Inkscape

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :