Skip to content

Commit 0ffd923

Browse files
committed
Merge branch 'develop'
2 parents ddb377f + a60162a commit 0ffd923

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2495
-841
lines changed

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
## [Unreleased]
44

5+
## [v2.0.0] - 25.10.2023
6+
7+
### Added
8+
9+
- Added default Krita, Photoshop, ArtRage and Leonardo layouts.
10+
- Now, the toolbar will automatically show up when you enter tablet mode, and hide when you enter desktop mode. This can be disabled in the settings.
11+
- Added `dock` and `undock` actions that allow to perform toolbar docking with a button instead of a context menu.
12+
- Added `docked_right`, `docked_left` and `docked_top` options to `visibility` property. Now, buttons can be shown only in some docking modes.
13+
14+
### Changed
15+
16+
- `layout` action now only needs layout name to be specified instead of its full path (for example, `action layout foxe` instead of `action layout files/layouts/foxe.yaml`). Paths will still work as long as the layout specified is in the `files/layouts` directory.
17+
- Layout properties `external_theme` and `theme` no longer work. Now, you must select a theme in the context menu independently from a layout. See "Migrating to 2.0" section for the full guide.
18+
- Theme properties `button_size`, `margin`, `min_opacity`, `max_opacity` have been moved directly to layout yaml. Themes can no longer influence these properties. See "Migrating to 2.0" section for the full guide.
19+
- Now the app will start in hidden mode.
20+
- Updated to .NET7
21+
- Optimized layout changing.
22+
23+
### Fixed
24+
25+
- Context menu color will now match theme color.
26+
- Quit button doesn't hang the app anymore.
27+
528
## [v1.2.0] - 24.10.2021
629

730
### Added
@@ -39,4 +62,4 @@
3962

4063
## [v1.0.0] - 26.09.2021
4164

42-
helo :D
65+
helo :D

README.md

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,28 @@ Grab the latest release from [this page](https://github.com/Martenfur/TabletFrie
3737

3838
Let's be honest - the default toolbars will probably not be enough for you. But that's ok. It's you who knows best what you need, this is why Tablet Friend is a great toolbar constructor first and a great toolbar second.
3939

40-
First, right-click the tray icon and press the 'open toolbar directory' button.
40+
First, right-click the tray icon and press the 'open files directory' button.
4141

4242
![menu](docs/pics/menu.png)
4343

4444
This will open a directory with a bunch of `.yaml` files. These are your toolbars - you can open them with any text editor you like. I know, I know, editing some config files directly may seem scary - luckily, Tablet Friend makes it as easy and intuitive as possible.
4545

4646
Let's make a new toolbar - create a file named `my_toolbar.yaml` in the `toolbars` directory, open it and paste this inside:
4747

48-
```yaml
48+
```yaml
4949
buttons:
5050
cut_button:
5151
action: ctrl+x
5252
text: cut
5353
```
5454

55-
Yes, it's that simple. Let's break down what we just wrote: `buttons` is a collection of buttons. This is where all your buttons will go. `cut_button` is the name of your button. **Note that all button names should be unique.** Its `action` is ctrl+x press. And it will display `text` that says "cut" on it. Now, right-click Tablet Friend toolbar and choose "my toolbar" from the list. You don't need to relaunch the program - it updates everything automatically. If you did everything correctly, you will see this:
55+
Yes, it's that simple. Let's break down what we just wrote: `buttons` is a collection of buttons. This is where all your buttons will go. `cut_button` is the name of your button. **Note that all button names should be unique.** Its `action` is a ctrl+x press. And it will display `text` that says "cut" on it. Now, right-click Tablet Friend toolbar and choose "my toolbar" from the list. You don't need to relaunch the program - it updates everything automatically. If you did everything correctly, you will see this:
5656

5757
![s1](docs/pics/s1.png)
5858

59-
In just four lines, we got ourselves a working button! But obviously, this is not enough for a functional toolbar. Let's add some more:
59+
In just four lines, we got ourselves a working button! But obviously, this is not enough for a functional toolbar. Let's add some more and some cosmetics:
6060

61-
```yaml
61+
```yaml
6262
buttons:
6363
cut_button:
6464
action: ctrl+x
@@ -92,7 +92,7 @@ Because there is enough space now, all buttons can fit on the same line. You can
9292
9393
However, what if you want to space out your buttons, or create a specific shape out of your buttons? For that, Tablet Friend has spacers. Change your config to look like this:
9494
95-
```yaml
95+
```yaml
9696
layout_width: 2
9797
buttons:
9898
cut_button:
@@ -119,9 +119,71 @@ Press Ctrl+S and your toolbar will now have a line of space in-between the butto
119119

120120
It is **VERY IMPORTANT** that you use tab characters ` ` instead of spaces for your indents. Indents do matter, since they tell the config what should go where. You *can* use spaces if you really want to, but keep in mind that all the default layouts use tabs, and tabs and spaces **should never mix** in one config.
121121

122+
### App-specific layouts
123+
124+
Having a layout is great but what if you want to have one layout for your drawing app, another for note taking and a completely separate one for web browsing? You're in luck because since version 2.0, Tablet Friend has app-specific layout support!
125+
126+
Simply add this line to the top of your layout config:
127+
```yaml
128+
app: mspaint
129+
```
130+
And now, every time we open Microsoft Paint, the layout will automatically switch to this one. But how do we know what exact name an app has?
131+
For this, you must focus on the app you want, right-click the Tablet Friend tray icon, select `settings` and look at the `focused app` label. It always tells the app you're focusing on.
132+
![app_name](docs/pics/app_name.png)
133+
134+
You can also use wildcards:
135+
```yaml
136+
app: app_name # Will match only app_name exactly.
137+
app: app_name* # Will match any app name that starts with app_name. For example, app_name_v_1.0
138+
app: "*app_name*" # Will match any app name that contains app_name. Note that if you're putting a * symbol in the beginning, you need to use quotes.
139+
```
140+
141+
If you switch to an app that doesn't have an app-spesific layout, it will switch to the last manually selected layout.
142+
143+
You can also disable automatic switching altogether by going into `settings` and pressing the `disable per-app layouts` button.
144+
145+
**NOTE**: In order for transition between layouts to be smooth and quick, `layout_width`, `button_size` and `margin` should be exactly the same between layouts.
146+
122147
This, of course, are not all the features Tablet Friend offers. You can check out a more [advanced example](TabletFriend/TabletFriend/files/layouts/sample_layout.yaml) with all features listed.
123148

149+
## Migrating to 2.0
150+
151+
Starting with the version 2.0.0, layout-specific themes are no longer supported. Instead, you can choose a theme in the context menu that will be applied to all toolbars.
152+
153+
![themes](docs/pics/themes.png)
154+
155+
This means, the layout structure has changed a little bit.
156+
157+
- Layout properties `external_theme` and `theme` no longer work.
158+
- Theme properties `button_size`, `margin`, `min_opacity`, `max_opacity` have been moved directly to layout yaml. Themes can no longer influence these properties.
159+
160+
An example of 1.0 to 2.0 migration for a layout:
161+
162+
```yaml
163+
# old layout
164+
layout_width: 4
165+
external_theme: files/themes/default.yaml
166+
theme:
167+
button_size: 14
168+
169+
buttons:
170+
hide:
171+
action: a
172+
text: "a"
173+
174+
# new layout
175+
layout_width: 4
176+
button_size: 14
177+
margin: 8
178+
179+
buttons:
180+
hide:
181+
action: a
182+
text: "a"
183+
184+
```
124185

186+
Note that unmodified 1.0 layouts and themes will still function but may get rendered differently.
125187

126188
## Making Tablet Friend better
127189

TabletFriend/TabletFriend/Actions/ButtonActionResolver.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public static class ButtonActionResolver
1616
private const string _repeatKeyword = "repeat ";
1717
private const string _hideKeyword = "hide";
1818

19+
private const string _dockKeyword = "dock ";
20+
private const string _undockKeyword = "undock";
21+
1922

2023
public static ButtonAction Resolve(string actionString)
2124
{
@@ -61,6 +64,14 @@ public static ButtonAction Resolve(string actionString)
6164
{
6265
return ResolveHideAction();
6366
}
67+
if (actionString.StartsWith(_dockKeyword))
68+
{
69+
return ResolveDockAction(actionString.Substring(_dockKeyword.Length));
70+
}
71+
if (actionString.StartsWith(_undockKeyword))
72+
{
73+
return ResolveUndockAction();
74+
}
6475

6576
return new KeyAction(StringToKeyCode(actionString));
6677
}
@@ -91,6 +102,12 @@ private static ButtonAction ResolveRepeatAction(string actionString) =>
91102

92103
private static ButtonAction ResolveHideAction() =>
93104
new HideAction();
105+
106+
private static ButtonAction ResolveDockAction(string actionString) =>
107+
new DockAction(actionString);
108+
109+
private static ButtonAction ResolveUndockAction() =>
110+
new UndockAction();
94111

95112

96113
public static ButtonAction[] Resolve(string[] actionStrings)

TabletFriend/TabletFriend/Actions/CmdAction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public CmdAction(string cmd)
1212
_cmd = cmd;
1313
}
1414

15-
public async override Task Invoke()
15+
public override Task Invoke()
1616
{
1717
var process = new Process();
1818
var startInfo = new ProcessStartInfo();
@@ -21,6 +21,7 @@ public async override Task Invoke()
2121
startInfo.Arguments = "/C " + _cmd;
2222
process.StartInfo = startInfo;
2323
process.Start();
24+
return Task.CompletedTask;
2425
}
2526
}
2627
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Threading.Tasks;
2+
using WpfAppBar;
3+
4+
namespace TabletFriend.Actions
5+
{
6+
public class DockAction : ButtonAction
7+
{
8+
private DockingMode _side = DockingMode.None;
9+
public DockAction(string side)
10+
{
11+
side = side.Trim();
12+
if (side == "left")
13+
_side = DockingMode.Left;
14+
if (side == "right")
15+
_side = DockingMode.Right;
16+
if (side == "top")
17+
_side = DockingMode.Top;
18+
}
19+
20+
public override Task Invoke()
21+
{
22+
EventBeacon.SendEvent(Events.DockingChanged, _side);
23+
return Task.CompletedTask;
24+
}
25+
}
26+
}

TabletFriend/TabletFriend/Actions/HideAction.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ namespace TabletFriend.Actions
44
{
55
public class HideAction : ButtonAction
66
{
7-
public override async Task Invoke() =>
8-
EventBeacon.SendEvent("toggle_minimize");
7+
public override Task Invoke()
8+
{
9+
EventBeacon.SendEvent(Events.ToggleMinimize);
10+
return Task.CompletedTask;
11+
}
912
}
1013
}

TabletFriend/TabletFriend/Actions/KeyAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class KeyAction : ButtonAction
88
{
99
private readonly KeyCode[] _keys;
1010

11-
public KeyAction(KeyCode[] keys)
11+
public KeyAction(params KeyCode[] keys)
1212
{
1313
_keys = keys;
1414
}

TabletFriend/TabletFriend/Actions/LayoutAction.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.IO;
2+
using System.Threading.Tasks;
23

34
namespace TabletFriend.Actions
45
{
@@ -11,7 +12,10 @@ public LayoutAction(string layout)
1112
_layout = layout;
1213
}
1314

14-
public override async Task Invoke() =>
15-
EventBeacon.SendEvent("change_layout", _layout);
15+
public override Task Invoke()
16+
{
17+
EventBeacon.SendEvent(Events.ChangeLayout, Path.GetFileNameWithoutExtension(_layout));
18+
return Task.CompletedTask;
19+
}
1620
}
1721
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Threading.Tasks;
2+
using WpfAppBar;
3+
4+
namespace TabletFriend.Actions
5+
{
6+
public class UndockAction : ButtonAction
7+
{
8+
public override Task Invoke()
9+
{
10+
EventBeacon.SendEvent(Events.DockingChanged, DockingMode.None);
11+
return Task.CompletedTask;
12+
}
13+
}
14+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Windows.Automation;
5+
6+
namespace TabletFriend
7+
{
8+
public class AppFocusMonitor : IDisposable
9+
{
10+
public HashSet<string> IgnoredApps = new HashSet<string>
11+
{
12+
"TabletFriend",
13+
"explorer" // Explorer takes over when you click the taskbar.
14+
};
15+
16+
public string FocusedApp { get; private set; }
17+
18+
public event Action<string> OnAppChanged;
19+
20+
public AppFocusMonitor()
21+
{
22+
Automation.AddAutomationFocusChangedEventHandler(OnFocusChanged);
23+
}
24+
25+
26+
private void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e)
27+
{
28+
try
29+
{
30+
var focusedElement = (AutomationElement)sender;
31+
if (focusedElement != null)
32+
{
33+
using (var process = Process.GetProcessById(focusedElement.Current.ProcessId))
34+
{
35+
if (!IgnoredApps.Contains(process.ProcessName) && FocusedApp != process.ProcessName)
36+
{
37+
FocusedApp = process.ProcessName;
38+
OnAppChanged?.Invoke(FocusedApp);
39+
}
40+
}
41+
}
42+
}
43+
catch
44+
{ }
45+
}
46+
47+
48+
public void Dispose()
49+
{
50+
Automation.RemoveAutomationFocusChangedEventHandler(OnFocusChanged);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)