Skip to content

Commit

Permalink
Added "--corner-size" option and various fixes
Browse files Browse the repository at this point in the history
Added "--corner-size" option. Task view whitelisted from full screen applications
  • Loading branch information
LucaReggiannini authored Jul 3, 2023
1 parent f77d7e2 commit 185fb2a
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions winycorners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ This tool wants to imitate the hot corners of Gnome Desktop 40+.
class HotCornerForm : System.Windows.Forms.Form {


public HotCornerForm(string position, bool enhancedTaskView) {
public HotCornerForm(string position, bool enhancedTaskView, short cornerSize) {
/* Create an invisible Windows Form */
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;

HotCorner hc = new HotCorner(position, enhancedTaskView);
HotCorner hc = new HotCorner(position, enhancedTaskView, cornerSize);
}


static void Main(string[] args) {

bool enhancedTaskView = false;
string position = "--top-left";
short cornerSize = 8;

/* Parse arguments */
if (args == null || args.Length == 0)
Expand All @@ -46,22 +47,31 @@ static void Main(string[] args) {
if (args[c]=="--enhanced-task-view") {
enhancedTaskView = true;
}
else if (args[c]=="--top-left" || args[c]=="--bottom-left" || args[0]=="--top-right" || args[0]=="--bottom-right") {
else if (args[c]=="--top-left" || args[c]=="--bottom-left" || args[c]=="--top-right" || args[c]=="--bottom-right") {
position=args[c];
}
else if (args[c]=="--corner-size") {
try {
cornerSize=short.Parse(args[c+1]);
c=c+1;
} catch {
help();
}
}
else
help();
}

System.Windows.Forms.Application.Run(new HotCornerForm(position, enhancedTaskView));
System.Windows.Forms.Application.Run(new HotCornerForm(position, enhancedTaskView, cornerSize));
}

}


static void help() {
MessageBox.Show(@"
WinYcorners
WinYcorners v1.5.0
https://github.com/LucaReggiannini/winycorners/
Sets a hot-corner that shows the Task View on mouse hover.
Expand All @@ -75,6 +85,9 @@ winycorners [OPTIONS] [POSITION]
Hides taskbar and maximize the desktop working area.
Show the taskbar only when taskview is visible (like Gnome)
--corner-size
The size of the hot corner in pixels. Default value is 8px
POSITION:
--top-left
--top-right
Expand All @@ -89,12 +102,12 @@ Show the taskbar only when taskview is visible (like Gnome)

class HotCorner {

int SCREEN_HEIGHT = Screen.PrimaryScreen.Bounds.Height;
int SCREEN_WIDTH = Screen.PrimaryScreen.Bounds.Width;
const short HOT_CORNER_SIZE = 8;
int SCREEN_HEIGHT = Screen.PrimaryScreen.Bounds.Height;
int SCREEN_WIDTH = Screen.PrimaryScreen.Bounds.Width;
// const short HOT_CORNER_SIZE = 8; // Corner size is now passed as argument
const short REFRESH_TIME = 10;

public HotCorner(string position, bool enhancedTaskView) {
public HotCorner(string position, bool enhancedTaskView, short HOT_CORNER_SIZE) {

/* Defining hot corner size */
Size s = new Size(HOT_CORNER_SIZE, HOT_CORNER_SIZE);
Expand All @@ -116,23 +129,23 @@ public HotCorner(string position, bool enhancedTaskView) {

while(true) {

if (ForegroundDetect.CheckFullScreen()==true) {
if (ForegroundDetect.CheckFullScreen()==false || IsTaskViewVisible()==true) {
/* Trigger hot corner based on the cursor position.
If the left mouse button is pressed the hot corner is not triggered: maybe a drag and drop operation is in progress */
If the left mouse button is pressed the hot corner is not triggered: maybe a drag and drop operation is in progress.
Note: hot corner is not triggered if there is a full screen application.
Windows 11 task view is considered a full screen application so is white
listed using "|| IsTaskViewVisible()==true" in the conditional block. */
if (hotCorner.Contains(new Point(Cursor.Position.X, Cursor.Position.Y))==true && isDown(Keys.LButton)==false) {
/* FIX for "--enhanced-task-view" on Windows 11:
Seems like Windows 11 can't modify Taskbar visibility when your are already in Task View
so set SetTaskbarVisible(true) by default when the hot corner is triggered then wait some
time (see "Thread.Sleep(300);" later) and finally check if Task View is visible or not in
order to update the taskbar visibility */
if (enhancedTaskView==true) { SetTaskbarVisible(true); }
SetTaskbarVisible(true);
if (triggeredHotCorner == false) {
triggeredHotCorner = true;
SwitchTaskView();
}
}
else if (hotCorner.Contains(new Point(Cursor.Position.X, Cursor.Position.Y))==false && triggeredHotCorner)
else if (hotCorner.Contains(new Point(Cursor.Position.X, Cursor.Position.Y))==false && triggeredHotCorner) {
triggeredHotCorner = false;
}
Thread.Sleep(300);
if (enhancedTaskView==true) {
/* Make sure that the desktop working area is always full size */
Expand Down Expand Up @@ -304,7 +317,7 @@ public static bool CheckFullScreen() {
RECT appBounds;
GetWindowRect(hWnd, out appBounds);
var screenBounds = Screen.FromHandle(hWnd).Bounds;
return !((appBounds.Bottom - appBounds.Top) == screenBounds.Height && (appBounds.Right - appBounds.Left) == screenBounds.Width);
return (appBounds.Bottom - appBounds.Top) == screenBounds.Height && (appBounds.Right - appBounds.Left) == screenBounds.Width;
}

[StructLayout(LayoutKind.Sequential)]
Expand Down

0 comments on commit 185fb2a

Please sign in to comment.