Skip to content

Commit 0071969

Browse files
committed
Debugging and more hotkeys
1 parent a52fe67 commit 0071969

3 files changed

Lines changed: 87 additions & 13 deletions

File tree

ContextSwitch/ContextSwitch.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
<UseWinUI>true</UseWinUI>
1313
<EnableMsixTooling>true</EnableMsixTooling>
1414
<WindowsSDKPackageVersion>10.0.26100.38</WindowsSDKPackageVersion>
15+
<Configurations>Debug;Release;DebugUnpackaged</Configurations>
1516
</PropertyGroup>
16-
<PropertyGroup>
17-
<!--<WindowsPackageType>None</WindowsPackageType>-->
18-
</PropertyGroup>
17+
<PropertyGroup Condition="'$(Configuration)'=='DebugUnpackaged'">
18+
<WindowsPackageType>None</WindowsPackageType>
19+
<DefineConstants>$(DefineConstants);UNPKG</DefineConstants>
20+
</PropertyGroup>
1921
<ItemGroup>
2022
<None Remove="Assets\ContextSwitchIcon.png" />
2123
</ItemGroup>

ContextSwitch/FloatingTimer.cs

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Numerics;
1616
using Microsoft.UI.Composition;
1717
using static ContextSwitch.Controls;
18+
using Microsoft.UI.Xaml.Controls.Primitives;
1819

1920
namespace ContextSwitch;
2021

@@ -93,24 +94,84 @@ private void FloatingTimer_Loaded(object sender, RoutedEventArgs e)
9394
animation.Target = nameof(contentVisual.Opacity);
9495
contentVisual.ImplicitAnimations[nameof(contentVisual.Opacity)] = animation;
9596
}
96-
97+
bool isCtrlDown = false;
98+
#if UNPKG
99+
public const string HOTKEY_MAIN = "R-ALT";
100+
#else
101+
public const string HOTKEY_MAIN = "R-CTRL";
102+
#endif
97103
private void LowLevelKeyboard_KeyPressed(KeyboardHookInfo eventDetails, KeyboardState state, ref bool Handled)
98104
{
105+
bool isDown = state is KeyboardState.KeyDown or KeyboardState.SystemKeyDown;
106+
#if UNPKG
107+
// Use RSHIFT for debugging
108+
if (eventDetails.KeyCode == WinWrapper.Input.VirtualKey.RMENU)
109+
#else
99110
if (eventDetails.KeyCode == WinWrapper.Input.VirtualKey.RCONTROL)
111+
#endif
100112
{
101-
bool isDown = state is KeyboardState.KeyDown or KeyboardState.SystemKeyDown;
102-
if (keyReset)
103-
{
104-
if (isDown) Start(resetTimerDuration);
105-
}
106-
else
113+
Handled = true;
114+
isCtrlDown = isDown;
115+
if (!keyReset)
107116
{
108-
if (isDown)
117+
if (isCtrlDown)
118+
{
109119
Content.Opacity = 1;
120+
ToHide = null;
121+
}
110122
else
111123
ToHide = DateTime.Now + TimeSpan.FromSeconds(3);
112124
}
113125
}
126+
if (isCtrlDown && eventDetails.KeyCode == WinWrapper.Input.VirtualKey.UP)
127+
{
128+
Handled = true;
129+
if (isDown)
130+
{
131+
if (IsTimerRunning)
132+
{
133+
endtime += TimeSpan.FromMinutes(1);
134+
TimerCallback();
135+
}
136+
else
137+
Start(TimeSpan.FromMinutes(1));
138+
}
139+
}
140+
if (isCtrlDown && eventDetails.KeyCode == WinWrapper.Input.VirtualKey.DOWN)
141+
{
142+
Handled = true;
143+
if (isDown && IsTimerRunning)
144+
{
145+
endtime -= TimeSpan.FromMinutes(1);
146+
TimerCallback();
147+
}
148+
}
149+
if (isCtrlDown && eventDetails.KeyCode == WinWrapper.Input.VirtualKey.RETURN)
150+
{
151+
Handled = true;
152+
if (isDown && keyReset)
153+
{
154+
Start(resetTimerDuration);
155+
}
156+
}
157+
if (isCtrlDown && eventDetails.KeyCode == WinWrapper.Input.VirtualKey.LEFT)
158+
{
159+
Handled = true;
160+
if (isDown)
161+
{
162+
Flyout flyout = null!;
163+
flyout = new Flyout
164+
{
165+
SystemBackdrop = new MicaBackdrop(),
166+
Content = VStack(center: true,
167+
Text("Quick Actions Page Coming Soon!"),
168+
new Button { Content = "Cool!" }.WithCustomCode(x => x.Click += (_, _) => flyout.Hide())
169+
),
170+
ShouldConstrainToRootBounds = false
171+
};
172+
flyout.ShowAt(Content, new() { Placement = FlyoutPlacementMode.BottomEdgeAlignedLeft});
173+
}
174+
}
114175
}
115176

116177
void UpdateSize()
@@ -181,7 +242,7 @@ void TimerCallback()
181242
Content.Opacity = 1;
182243
keyReset = true;
183244
((StackPanel)Content).Children.Add(
184-
HStack(center: true, Key("R-CTRL", new(0, 0, right: 5, 0)), Text("Reset Timer", TextLineBounds.Tight)));
245+
HStack(center: true, Key($"{HOTKEY_MAIN} + Enter", new(0, 0, right: 5, 0)), Text("Reset Timer", TextLineBounds.Tight)));
185246
UpdateSize();
186247
}
187248
}

ContextSwitch/MainWindow.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
using WinUIEx;
1212
using WindowApi = WinWrapper.Windowing.Window;
1313
using static ContextSwitch.Controls;
14+
using Windows.Storage;
15+
using System.Reflection;
16+
using System.IO;
1417
namespace ContextSwitch;
1518

1619
class MainWindow : Window
@@ -23,6 +26,14 @@ public MainWindow()
2326
w.Size = new(550, 450);
2427
var d = w.CurrentDisplay.WorkingAreaBounds;
2528
w.Location = new((d.Width - w.Size.Width) / 2 + d.Left, (d.Height - w.Size.Height) / 2 + d.Top);
29+
#if UNPKG
30+
string path = AppContext.BaseDirectory;
31+
#else
32+
string path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
33+
#endif
34+
w.LargeIcon = WinWrapper.Icon.FromHandle(
35+
new System.Drawing.Bitmap(Path.Join(path, "Assets", "ContextSwitchIcon.png")).GetHicon()
36+
);
2637
}
2738
void InitMain()
2839
{
@@ -55,7 +66,7 @@ void InitMain()
5566
SelectedTime = TimeSpan.FromMinutes(25),
5667
},
5768
btn = new Button() { Content = "Start Timer" },
58-
HStack(center: true, Text("Tip: Hold"), Key("R-CTRL"), Text("to show timer"))
69+
HStack(center: true, Text("Tip: Hold"), Key(FloatingTimer.HOTKEY_MAIN), Text("to show timer"))
5970
)
6071
.WithCustomCode(x =>
6172
{

0 commit comments

Comments
 (0)