Skip to content

Commit

Permalink
app: add key Shift+Left/Right to move window between screens
Browse files Browse the repository at this point in the history
  • Loading branch information
nomi-san committed Jun 6, 2024
1 parent 2331de9 commit c8f8a28
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/Languages/vi.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<system:String x:Key="lang_name">Tiếng Việt</system:String>

<!--Interface-->
<system:String x:Key="t_add_display">Cắm màn hình</system:String>
<system:String x:Key="t_hint_add_display_first">Hãy cắm màn hình ảo!</system:String>
<system:String x:Key="t_add_display">Thêm màn hình</system:String>
<system:String x:Key="t_hint_add_display_first">Hãy thêm màn hình ảo!</system:String>
<system:String x:Key="t_custom">Tùy chỉnh...</system:String>
<system:String x:Key="t_apply">Áp dụng</system:String>
<system:String x:Key="t_parent_gpu">GPU nguồn</system:String>
Expand Down Expand Up @@ -42,7 +42,7 @@
<system:String x:Key="t_msg_custom_access_denied">Không thể áp dụng độ phân giải tùy chỉnh, quyền truy cập bị từ chối!</system:String>
<system:String x:Key="t_msg_custom_invalid_slot">Giá trị không hợp lệ ở slot #{0}.</system:String>

<system:String x:Key="t_msg_exceeded_display_limit">Không thể cắm thêm màn hình ảo, bạn đã đạt đến con số giới hạn ({0}).</system:String>
<system:String x:Key="t_msg_exceeded_display_limit">Không thể thêm thêm màn hình ảo, bạn đã đạt đến con số giới hạn ({0}).</system:String>
<system:String x:Key="t_msg_prompt_leave_all">Tất cả màn hình ảo sẽ bị tháo bỏ.\nBạn có muốn thoát không?.</system:String>

<system:String x:Key="t_msg_driver_status">Trạng thái driver</system:String>
Expand Down
1 change: 1 addition & 0 deletions app/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
WindowStartupLocation="CenterScreen"
Loaded="Window_Loaded"
Unloaded="Window_Unloaded"
KeyDown="Window_KeyDown"
>
<Grid MouseDown="Grid_MouseDown">
<Grid.Background>
Expand Down
37 changes: 37 additions & 0 deletions app/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,42 @@ private void LanguageText_MouseEvent(object sender, MouseButtonEventArgs e)
if (e.LeftButton == MouseButtonState.Released)
(sender as TextBlock).ContextMenu.IsOpen = true;
}

private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (!e.IsRepeat &&
(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)))
{
var screen = System.Windows.Forms.Screen.FromHandle(Handle);
if (screen != null)
{
var screens = System.Windows.Forms.Screen.AllScreens;

int index = -1, nextIndex;
for (int i = 0; i < screens.Length; i++)
if (screens[i].Bounds.Contains(screen.Bounds))
index = i;

if (index != -1)
{
if (e.Key == Key.Left)
nextIndex = index - 1;
else if (e.Key == Key.Right)
nextIndex = index + 1;
else return;

if (nextIndex >= screens.Length) nextIndex = 0;
else if (nextIndex < 0) nextIndex = screens.Length - 1;

if (index != nextIndex)
{
var wa = screens[nextIndex].WorkingArea;
Left = wa.Location.X + (wa.Width - RenderSize.Width) / 2;
Top = wa.Location.Y + (wa.Height - RenderSize.Height) / 2;
}
}
}
}
}
}
}

0 comments on commit c8f8a28

Please sign in to comment.