Skip to content

Commit

Permalink
Remember last used stylus
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmhewitt committed Jul 21, 2019
1 parent 2945299 commit c8c0152
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Backend/WacomToolMap.vala
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,26 @@ public class Wacom.Backend.WacomToolMap : GLib.Object {

return tool;
}

public Gee.ArrayList<WacomTool> list_tools (WacomDevice device) {
var styli = new Gee.ArrayList<WacomTool> ();

var key = get_device_key (device);
var tablet_tools = tablet_map[key];
if (tablet_tools != null) {
styli.add_all (tablet_map[key]);
}

if (no_serial_tool_map.has_key (key)) {
var no_serial_tool = no_serial_tool_map[key];
if (no_serial_tool == null) {
no_serial_tool = new WacomTool (0, 0, device);
no_serial_tool_map[key] = no_serial_tool;
}

styli.add (no_serial_tool);
}

return styli;
}
}
11 changes: 9 additions & 2 deletions src/Plug.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Wacom.Plug : Switchboard.Plug {
private Gee.HashMap<Backend.Device, Backend.WacomDevice>? devices = null;

private Backend.WacomTool? last_stylus = null;
private Backend.WacomToolMap tool_map;

public Plug () {
var settings = new Gee.TreeMap<string, string?> (null, null);
Expand All @@ -57,6 +58,8 @@ public class Wacom.Plug : Switchboard.Plug {
devices.clear ();
}

tool_map = Backend.WacomToolMap.get_default ();

stylus_view = new StylusView ();
tablet_view = new TabletView ();

Expand Down Expand Up @@ -128,7 +131,6 @@ public class Wacom.Plug : Switchboard.Plug {
}

var serial = tool.get_serial ();
var tool_map = Backend.WacomToolMap.get_default ();

var stylus = tool_map.lookup_tool (wacom_device, serial);
if (stylus == null) {
Expand Down Expand Up @@ -167,7 +169,12 @@ public class Wacom.Plug : Switchboard.Plug {
warning ("Error initializing Wacom device: %s", e.message);
return;
}
}

var tools = tool_map.list_tools (devices[d]);
if (tools.size > 0) {
stylus_view.set_device (tools[0]);
}
}

private void update_current_page () {
foreach (var device in devices.keys) {
Expand Down

0 comments on commit c8c0152

Please sign in to comment.