Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit d87b5fb

Browse files
author
skver0
committed
i hate windows
fixed a bug when you click on your fucking desktop the bar hides itself. did you guys know that the DESKTOP is a fucking window that cant be checked for just using API calls? now this is epic
1 parent 0e991aa commit d87b5fb

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

Main.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ namespace x1
1515
public partial class Main : Form
1616
{
1717
#region epic dLLimportz
18+
/// <summary>
19+
/// Most of this is from pinvoke.net lol
20+
/// </summary>
21+
/// <returns></returns>
22+
23+
[DllImport("user32.dll")]
24+
static extern IntPtr GetShellWindow();
25+
26+
[DllImport("user32.dll", SetLastError = false)]
27+
static extern IntPtr GetDesktopWindow();
28+
1829
[DllImport("user32.dll")]
1930
private static extern bool SetProcessDPIAware();
2031

@@ -107,7 +118,7 @@ void CheckBattery()
107118
int batterynumber = Convert.ToInt32(battery.BatteryLifePercent.ToString("P0").Trim(new Char[] { '%' }));
108119
if (battery.BatteryChargeStatus.ToString() != "NoSystemBattery")
109120
{
110-
if (batterynumber <= 100 && batterynumber >=80)
121+
if (batterynumber <= 100 && batterynumber >= 80)
111122
{
112123
btry.Text = "[----]";
113124
}
@@ -150,10 +161,24 @@ public string GetSpotifyTrackInfo()
150161

151162
if (string.Equals(proc.MainWindowTitle, "Spotify", StringComparison.InvariantCultureIgnoreCase))
152163
return " Paused";
153-
164+
154165
return proc.MainWindowTitle;
155166
}
156167

168+
bool IsOnDesktop()
169+
{
170+
Process[] proc = Process.GetProcesses();
171+
IntPtr current = GetForegroundWindow();
172+
173+
foreach (Process x in proc)
174+
{
175+
if (x.MainWindowHandle == current)
176+
{
177+
return false;
178+
}
179+
}
180+
return true;
181+
}
157182

158183
#region haha im epic
159184
private void t1_Tick(object sender, EventArgs e)
@@ -170,8 +195,12 @@ private void t1_Tick(object sender, EventArgs e)
170195

171196
//totally not for debugging
172197
//label1.Text = Convert.ToString(edited.Width) + "E" + Convert.ToString(edited.Height) + " " + Convert.ToString(window.Height) + "W" + Convert.ToString(window.Height) + " " + Convert.ToString(window.X) + "X" + Convert.ToString(window.Y);
198+
//label1.Text = Convert.ToString(GetForegroundWindow());
199+
//label1.Text = Convert.ToString(GetDesktopWindow());
173200

174-
if (edited.Height >= Screen.PrimaryScreen.Bounds.Height && edited.Width >= Screen.PrimaryScreen.Bounds.Width)
201+
//this is so fucking retarded that i dont even know why it doesnt work only if i add a retarded bool that checks every process this is anoying. install gentoo
202+
203+
if (edited.Height >= Screen.PrimaryScreen.Bounds.Height && edited.Width >= Screen.PrimaryScreen.Bounds.Width && GetActiveWindowTitle() != "" && GetForegroundWindow() != null && GetForegroundWindow() != GetShellWindow() && GetForegroundWindow() != GetDesktopWindow() && !IsOnDesktop())
175204
{
176205
Hide();
177206
}
@@ -181,7 +210,7 @@ private void t1_Tick(object sender, EventArgs e)
181210
}
182211

183212
if (battery.BatteryChargeStatus.ToString() != "NoSystemBattery")
184-
CheckBattery();
213+
CheckBattery();
185214

186215
title.Text = GetActiveWindowTitle();
187216
time.Text = DateTime.Now.ToString("HH:mm");

0 commit comments

Comments
 (0)