Skip to content

Commit

Permalink
Make FilterModifierKeys an extension method so we don't duplicate code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Mar 11, 2015
1 parent 005ad15 commit d932f37
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
15 changes: 15 additions & 0 deletions Pinta.Core/Extensions/GdkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ public static bool IsControlPressed (this EventButton ev)
return ev.State.IsControlPressed ();
}

/// <summary>
/// Filters out all modifier keys except Ctrl/Shift/Alt. This prevents Caps Lock, Num Lock, etc
/// from appearing as active modifier keys.
/// </summary>
public static ModifierType FilterModifierKeys (this ModifierType current_state)
{
var state = Gdk.ModifierType.None;

state |= (current_state & Gdk.ModifierType.ControlMask);
state |= (current_state & Gdk.ModifierType.ShiftMask);
state |= (current_state & Gdk.ModifierType.Mod1Mask);

return state;
}

public static Cairo.PointD GetPoint (this EventButton ev)
{
return new Cairo.PointD (ev.X, ev.Y);
Expand Down
17 changes: 1 addition & 16 deletions Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected override bool OnExposeEvent (EventExpose e)
protected override bool OnScrollEvent (EventScroll evnt)
{
// Allow the user to zoom in/out with Ctrl-Mousewheel
if (FilterModifierKeys(evnt.State) == ModifierType.ControlMask) {
if (evnt.State.FilterModifierKeys () == ModifierType.ControlMask) {
switch (evnt.Direction) {
case ScrollDirection.Down:
case ScrollDirection.Right:
Expand Down Expand Up @@ -193,21 +193,6 @@ public void DoKeyReleaseEvent (object o, KeyReleaseEventArgs e)
{
PintaCore.Tools.CurrentTool.DoKeyRelease (this, e);
}

/// <summary>
/// Filters out all modifier keys except Ctrl/Shift/Alt. This prevents Caps Lock, Num Lock, etc
/// from appearing as active modifier keys.
/// </summary>
private ModifierType FilterModifierKeys (Gdk.ModifierType current_state)
{
ModifierType state = ModifierType.None;

state |= (current_state & ModifierType.ControlMask);
state |= (current_state & ModifierType.ShiftMask);
state |= (current_state & ModifierType.Mod1Mask);

return state;
}
#endregion
}
}
17 changes: 1 addition & 16 deletions Pinta/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,10 @@ private void MainWindow_KeyPressEvent (object o, KeyPressEventArgs e)

// If the canvas/tool didn't consume it, see if its a toolbox shortcut
if (e.RetVal == null || !(bool)e.RetVal)
if (FilterModifierKeys (e.Event.State) == Gdk.ModifierType.None)
if (e.Event.State.FilterModifierKeys () == Gdk.ModifierType.None)
PintaCore.Tools.SetCurrentTool (e.Event.Key);
}

/// <summary>
/// Filters out all modifier keys except Ctrl/Shift/Alt. This prevents Caps Lock, Num Lock, etc
/// from appearing as active modifier keys.
/// </summary>
private Gdk.ModifierType FilterModifierKeys (Gdk.ModifierType current_state)
{
var state = Gdk.ModifierType.None;

state |= (current_state & Gdk.ModifierType.ControlMask);
state |= (current_state & Gdk.ModifierType.ShiftMask);
state |= (current_state & Gdk.ModifierType.Mod1Mask);

return state;
}

[GLib.ConnectBefore]
private void MainWindow_KeyReleaseEvent (object o, KeyReleaseEventArgs e)
{
Expand Down

0 comments on commit d932f37

Please sign in to comment.