Skip to content

Commit

Permalink
Fix issues with grabbing focus in the canvas widget
Browse files Browse the repository at this point in the history
Doing this on the drawing area widget (which is inside a scroll window) seems to cause the scrollbars to reset back to 0. Grabbing focus on the parent canvas widget works better.

Fixes: PintaProject#698
  • Loading branch information
cameronwhite committed Apr 28, 2024
1 parent 54d3b18 commit 50863f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Pinta.Gui.Widgets/Widgets/Canvas/CanvasWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ public CanvasWindow (Document document)
scroll_controller.OnScroll += HandleScrollEvent;
vp.AddController (scroll_controller);

// The mouse handler in PintaCanvas grabs focus away from toolbar widgets.
Focusable = true;

Canvas = new PintaCanvas (this, document) {
Name = "canvas",
CanFocus = true,
};

// Rulers
Expand Down
8 changes: 4 additions & 4 deletions Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public PintaCanvas (CanvasWindow window, Document document)
CanvasWindow = window;
this.document = document;

Focusable = true;

cr = new CanvasRenderer (true, true);

// Keep the widget the same size as the canvas
Expand Down Expand Up @@ -77,8 +75,10 @@ public PintaCanvas (CanvasWindow window, Document document)
// Note we don't call click_controller.SetState (Gtk.EventSequenceState.Claimed) here, so
// that the CanvasWindow can also receive motion events to update the root window mouse position.

// A mouse click on the canvas should grab focus from any toolbar widgets, etc
GrabFocus ();
// A mouse click on the canvas should grab focus away from any toolbar widgets, etc
// Using the root canvas widget works best - if the drawing area is given focus, the scroll
// widget jumps back to the origin.
CanvasWindow.GrabFocus ();

// The canvas gets the button press before the tab system, so
// if this click is on a canvas that isn't currently the ActiveDocument yet,
Expand Down

0 comments on commit 50863f2

Please sign in to comment.