Skip to content

Commit 7f942a0

Browse files
committed
Implemented window lock/unlock to more easily set position and size
1 parent dcd230f commit 7f942a0

File tree

4 files changed

+107
-8
lines changed

4 files changed

+107
-8
lines changed

Background-Terminal/MainWindow.xaml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:tb="http://www.hardcodet.net/taskbar"
88
Title="Background Terminal"
99
Width="400"
10-
Height="340"
10+
Height="410"
1111
AllowsTransparency="True"
1212
Background="Transparent"
1313
Closed="MainWindow_Closed"
@@ -179,13 +179,15 @@
179179
<RowDefinition Height="30" />
180180
<RowDefinition Height="30" />
181181
<RowDefinition Height="30" />
182+
<RowDefinition Height="10" />
183+
<RowDefinition Height="30" />
182184
<RowDefinition Height="30" />
183185
<RowDefinition Height="30" />
184186
<RowDefinition Height="10" />
185187
<RowDefinition Height="100" />
186188
<RowDefinition Height="30" />
187189
</Grid.RowDefinitions>
188-
<Border Grid.RowSpan="7" Background="#F5F5F5" />
190+
<Border Grid.RowSpan="9" Background="#F5F5F5" />
189191
<Grid Grid.Row="0" VerticalAlignment="Center">
190192
<Grid.ColumnDefinitions>
191193
<ColumnDefinition Width="1*" />
@@ -263,6 +265,34 @@
263265
VerticalContentAlignment="Center" />
264266
</Grid>
265267
<Grid Grid.Row="3">
268+
<Border
269+
Height="1"
270+
Margin="10,0,10,0"
271+
BorderBrush="Gray"
272+
BorderThickness="1" />
273+
</Grid>
274+
<Grid Grid.Row="4">
275+
<Grid.ColumnDefinitions>
276+
<ColumnDefinition Width="1*" />
277+
<ColumnDefinition Width="1*" />
278+
</Grid.ColumnDefinitions>
279+
<Label
280+
Grid.Row="0"
281+
HorizontalAlignment="Center"
282+
Content="Window Status:"
283+
FontFamily="Yu Gothic UI Light" />
284+
<Grid Grid.Column="1">
285+
<Button
286+
x:Name="TerminalWindowLocked_Button"
287+
Margin="10,5"
288+
Click="TerminalWindowLockedButton_Click"
289+
Content="Locked"
290+
FontFamily="Yu Gothic UI Light"
291+
FontSize="10"
292+
Style="{StaticResource StandardButton1}" />
293+
</Grid>
294+
</Grid>
295+
<Grid Grid.Row="5">
266296
<Grid.ColumnDefinitions>
267297
<ColumnDefinition Width="1*" />
268298
<ColumnDefinition Width="1*" />
@@ -305,7 +335,7 @@
305335
FontFamily="Yu Gothic UI" />
306336
</Grid>
307337
</Grid>
308-
<Grid Grid.Row="4">
338+
<Grid Grid.Row="6">
309339
<Grid.ColumnDefinitions>
310340
<ColumnDefinition Width="1*" />
311341
<ColumnDefinition Width="1*" />
@@ -348,14 +378,14 @@
348378
FontFamily="Yu Gothic UI" />
349379
</Grid>
350380
</Grid>
351-
<Grid Grid.Row="5">
381+
<Grid Grid.Row="7">
352382
<Border
353383
Height="1"
354384
Margin="10,0,10,0"
355385
BorderBrush="Gray"
356386
BorderThickness="1" />
357387
</Grid>
358-
<Grid Grid.Row="6">
388+
<Grid Grid.Row="8">
359389
<Grid.RowDefinitions>
360390
<RowDefinition Height="30" />
361391
<RowDefinition Height="1*" />
@@ -434,7 +464,7 @@
434464
</ListBox.ItemTemplate>
435465
</ListBox>
436466
</Grid>
437-
<Grid Grid.Row="7">
467+
<Grid Grid.Row="9">
438468
<Grid.ColumnDefinitions>
439469
<ColumnDefinition Width="1*" />
440470
<ColumnDefinition Width="1" />

Background-Terminal/MainWindow.xaml.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public partial class MainWindow : Window
4848
private int _cmdProcessId;
4949

5050
private bool _terminalWindowActive = false;
51+
private bool _terminalWindowLocked = true;
5152

5253
private bool _awaitingKey1 = false;
5354
private bool _awaitingKey2 = false;
@@ -60,7 +61,7 @@ public MainWindow()
6061
InitializeComponent();
6162

6263
// Create TerminalWindow
63-
_terminalWindow = new TerminalWindow(SendCommand, KillChildren);
64+
_terminalWindow = new TerminalWindow(SendCommand, KillChildren, TerminalWindowUpdate);
6465
_terminalWindow.Show();
6566

6667
// Apply changes in terminal data to TerminalWindow
@@ -262,6 +263,15 @@ private void KillChildren()
262263
}
263264
}
264265
}
266+
267+
private void TerminalWindowUpdate()
268+
{
269+
PosX_TextBox.Text = _terminalWindow.Left.ToString();
270+
PosY_TextBox.Text = _terminalWindow.Top.ToString();
271+
272+
Width_TextBox.Text = _terminalWindow.Width.ToString();
273+
Height_TextBox.Text = _terminalWindow.Height.ToString();
274+
}
265275
#endregion
266276

267277
#region Event Handlers
@@ -281,6 +291,22 @@ private void TrayIcon_LeftMouseDown(object sender, RoutedEventArgs e)
281291
}
282292
}
283293

294+
private void TerminalWindowLockedButton_Click(object sender, RoutedEventArgs e)
295+
{
296+
if (_terminalWindowLocked)
297+
{
298+
_terminalWindowLocked = false;
299+
TerminalWindowLocked_Button.Content = "Unlocked";
300+
}
301+
else
302+
{
303+
_terminalWindowLocked = true;
304+
TerminalWindowLocked_Button.Content = "Locked";
305+
}
306+
307+
_terminalWindow.SetWindowLocked(_terminalWindowLocked);
308+
}
309+
284310
private void Key1Button_Click(object sender, RoutedEventArgs e)
285311
{
286312
Key1_Button.Content = "Press Key...";

Background-Terminal/TerminalWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
AllowsTransparency="True"
99
Background="Transparent"
1010
Loaded="TerminalWindow_Loaded"
11+
LocationChanged="TerminalWindow_LocationChanged"
12+
MouseDown="TerminalWindow_MouseDown"
1113
ResizeMode="NoResize"
1214
ShowInTaskbar="False"
15+
SizeChanged="TerminalWindow_SizeChanged"
1316
WindowStyle="None"
1417
mc:Ignorable="d">
1518
<Grid>

Background-Terminal/TerminalWindow.xaml.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,65 @@ public partial class TerminalWindow : Window
2020
public delegate void KillChildrenProc();
2121
private KillChildrenProc KillChildren;
2222

23+
public delegate void TerminalWindowUpdateProc();
24+
private TerminalWindowUpdateProc TerminalWindowUpdate;
25+
2326
private List<string> _commandHistory = new List<string>();
2427
private int _commandHistoryIndex = -1;
2528

29+
private bool _locked;
30+
2631
bool _ctrlDown = false;
2732

28-
public TerminalWindow(SendCommandProc sendCommand, KillChildrenProc killChildren)
33+
public TerminalWindow(SendCommandProc sendCommand, KillChildrenProc killChildren, TerminalWindowUpdateProc terminalWindowUpdate)
2934
{
3035
InitializeComponent();
3136

3237
SendCommand = sendCommand;
3338
KillChildren = killChildren;
39+
TerminalWindowUpdate = terminalWindowUpdate;
3440
}
3541

3642
public void UpdateTerminalDataTextBoxMargin() // I do what I want
3743
{
3844
TerminalData_TextBox.Margin = new Thickness(0, 0, 0, Input_TextBox.ActualHeight);
3945
}
4046

47+
public void SetWindowLocked(bool locked)
48+
{
49+
_locked = locked;
50+
51+
if (locked)
52+
{
53+
this.Background = Brushes.Transparent;
54+
this.ResizeMode = ResizeMode.NoResize;
55+
TerminalData_TextBox.IsHitTestVisible = true;
56+
}
57+
else
58+
{
59+
this.Background = Brushes.Gray;
60+
this.ResizeMode = ResizeMode.CanResizeWithGrip;
61+
TerminalData_TextBox.IsHitTestVisible = false;
62+
}
63+
}
64+
4165
#region Event Handlers
66+
private void TerminalWindow_MouseDown(object sender, MouseEventArgs e)
67+
{
68+
if (!_locked && e.LeftButton == MouseButtonState.Pressed)
69+
this.DragMove();
70+
}
71+
72+
private void TerminalWindow_LocationChanged(object sender, EventArgs e)
73+
{
74+
TerminalWindowUpdate();
75+
}
76+
77+
private void TerminalWindow_SizeChanged(object sender, RoutedEventArgs e)
78+
{
79+
TerminalWindowUpdate();
80+
}
81+
4282
private void TerminalDataTextBox_TextChanged(object sender, TextChangedEventArgs e)
4383
{
4484
TerminalData_TextBox.ScrollToEnd();

0 commit comments

Comments
 (0)