This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Main.cs
468 lines (399 loc) · 15.1 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace x1
{
public partial class Main : Form
{
#region epic dLLimportz
/// <summary>
/// Most of this is from pinvoke.net lol
/// </summary>
/// <returns></returns>
[DllImport("user32.dll")]
static extern IntPtr GetShellWindow();
[DllImport("user32.dll", SetLastError = false)]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out Rectangle lpRect);
[DllImport("user32.dll", SetLastError = true)]
private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
[DllImport("user32.dll")]
static extern ushort GetAsyncKeyState(int vKey);
public static bool IsKeyPushedDown(System.Windows.Forms.Keys vKey)
{
return 0 != (GetAsyncKeyState((int)vKey) & 0x8000);
}
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
private string GetActiveWindowTitle()
{
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
IntPtr handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
private static IntPtr m_hTaskBar;
public static void HideTaskBar()
{
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/x12nd"))
{
m_hTaskBar = FindWindow("Shell_SecondaryTrayWnd", null);
if ((int)m_hTaskBar != 0)
{
ShowWindow(m_hTaskBar, 0);
}
}
else
{
m_hTaskBar = FindWindow("Shell_TrayWnd", null);
if ((int)m_hTaskBar != 0)
{
ShowWindow(m_hTaskBar, 0);
}
}
}
#endregion
public int offset = 40;
bool helpdialog = false;
PowerStatus battery = SystemInformation.PowerStatus;
Help help = new Help();
publicbool publicbool = new publicbool();
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
public Main()
{
InitializeComponent();
if (File.Exists(appdata + "/x1custom"))
{
string checklenght;
using (StreamReader readdata = File.OpenText(appdata + "/x1custom"))
{
checklenght = readdata.ReadLine();
}
if (checklenght.Length < 3 && checklenght.Length > 0)
{
x1logo.Text = checklenght;
}
else
{
x1logo.Text = "x1";
}
x1logo.TextAlign = ContentAlignment.MiddleCenter;
}
else
{
x1logo.Text = "x1";
}
if (File.Exists(appdata + "/x1color"))
{
using (StreamReader readdata = File.OpenText(appdata + "/x1color"))
{
this.BackColor = Color.FromArgb(Convert.ToInt32(readdata.ReadLine()));
}
}
if (File.Exists(appdata + "/x1opacity"))
{
float igen;
using (StreamReader readdata = File.OpenText(appdata + "/x1opacity"))
{
igen = float.Parse(readdata.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);
this.Opacity = Convert.ToDouble(igen / 100);
}
}
if (File.Exists(appdata + "/x1offset"))
{
using (StreamReader readdata = File.OpenText(appdata + "/x1offset"))
{
offset = Convert.ToInt32(readdata.ReadLine());
}
}
}
public Screen GetSecondaryScreen()
{
if (Screen.AllScreens.Length == 1)
{
return null;
}
foreach (Screen screen in Screen.AllScreens)
{
if (screen.Primary == false)
{
return screen;
}
}
return null;
}
private void Main_Load(object sender, EventArgs e)
{
SetProcessDPIAware();
if (File.Exists(appdata + "/x1left"))
{
Width = 62;
spotifytrack.Anchor = AnchorStyles.Right;
seperator.Anchor = AnchorStyles.Right;
btry.Anchor = AnchorStyles.Right;
time.Anchor = AnchorStyles.Right;
panel_StuffHere.Anchor = AnchorStyles.Right;
Height = Screen.PrimaryScreen.Bounds.Height;
}
else
{
if (File.Exists(appdata + "/x12nd"))
{
spotifytrack.Anchor = AnchorStyles.Right;
seperator.Anchor = AnchorStyles.Right;
btry.Anchor = AnchorStyles.Right;
time.Anchor = AnchorStyles.Right;
panel_StuffHere.Anchor = AnchorStyles.Right;
if (Screen.AllScreens.Length > 1)
{
Screen secscreen = GetSecondaryScreen();
Width = secscreen.Bounds.Width;
}
}
else
{
spotifytrack.Anchor = AnchorStyles.Right;
seperator.Anchor = AnchorStyles.Right;
btry.Anchor = AnchorStyles.Right;
time.Anchor = AnchorStyles.Right;
panel_StuffHere.Anchor = AnchorStyles.Right;
Width = Screen.PrimaryScreen.Bounds.Width;
}
}
t1.Start();
HideTaskBar();
CheckBattery();
}
void CheckBattery()
{
int batterynumber = Convert.ToInt32(battery.BatteryLifePercent.ToString("P0").Trim(new Char[] { '%' }));
if (battery.BatteryChargeStatus.ToString() != "NoSystemBattery")
{
if (batterynumber <= 100 && batterynumber >= 80)
{
btry.Text = "[----]";
}
if (batterynumber <= 80 && batterynumber >= 70)
{
btry.Text = "[--- ]";
}
if (batterynumber <= 70 && batterynumber >= 50)
{
btry.Text = "[-- ]";
}
if (batterynumber <= 50 && batterynumber >= 20)
{
btry.Text = "[- ]";
}
if (batterynumber <= 20 && batterynumber >= 0)
{
btry.Text = "[ ]";
}
}
else
{
spotifytrack.Location = new Point(98, 10);
btry.Hide();
p_Media.Location = new Point(366, 6);
}
}
public string GetSpotifyTrackInfo()
{
var proc = Process.GetProcessesByName("Spotify").FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle));
if (proc == null)
return "";
if (string.Equals(proc.MainWindowTitle, "Spotify", StringComparison.InvariantCultureIgnoreCase))
return " Paused";
return proc.MainWindowTitle;
}
bool IsOnDesktop()
{
Process[] proc = Process.GetProcesses();
IntPtr current = GetForegroundWindow();
foreach (Process x in proc)
{
if (x.MainWindowHandle == current)
{
return false;
}
}
return true;
}
#region haha im epic
private void t1_Tick(object sender, EventArgs e)
{
caps caps = new caps();
if (File.Exists(appdata + "/x1left"))
{
// idfk how to do it its hard man please make a pull request thanks
Location = new Point(0, 0);
}
if (File.Exists(appdata + "/x1top"))
{
if (File.Exists(appdata + "/x12nd"))
{
Width = GetSecondaryScreen().Bounds.Width;
Location = GetSecondaryScreen().WorkingArea.Location;
}
else
{
Width = Screen.PrimaryScreen.Bounds.Width;
Location = new Point(0, 0);
}
}
else
{
if (!File.Exists(appdata + "/x1left"))
{
if (File.Exists(appdata + "/x12nd"))
{
if (GetSecondaryScreen() != null)
{
Width = GetSecondaryScreen().Bounds.Width;
Location = new Point(GetSecondaryScreen().WorkingArea.X, GetSecondaryScreen().Bounds.Height - offset);
// label1.Text = Convert.ToString(GetSecondaryScreen().WorkingArea.X);
}
}
else
{
Width = Screen.PrimaryScreen.Bounds.Width;
var ScreenHeight = Screen.PrimaryScreen.Bounds.Height;
Location = new Point(0, ScreenHeight - 40);
}
}
}
Rectangle window = new Rectangle();
Rectangle edited = new Rectangle();
GetWindowRect(GetForegroundWindow(), out window);
edited.Width = window.Width - window.X;
edited.Height = window.Height - window.Y;
//totally not for debugging
//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);
//label1.Text = Convert.ToString(GetForegroundWindow());
//label1.Text = Convert.ToString(GetDesktopWindow());
//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
if (!File.Exists(appdata + "/x12nd"))
{
if (edited.Height >= Screen.PrimaryScreen.Bounds.Height && edited.Width >= Screen.PrimaryScreen.Bounds.Width && GetActiveWindowTitle() != "" && GetForegroundWindow() != null && GetForegroundWindow() != GetShellWindow() && GetForegroundWindow() != GetDesktopWindow() && !IsOnDesktop())
{
Hide();
}
else
{
Show();
}
}
else
{
if (GetSecondaryScreen() != null)
{
if (edited.Height >= GetSecondaryScreen().Bounds.Height && edited.Width >= GetSecondaryScreen().Bounds.Width && GetActiveWindowTitle() != "" && GetForegroundWindow() != null && GetForegroundWindow() != GetShellWindow() && GetForegroundWindow() != GetDesktopWindow() && !IsOnDesktop())
{
Hide();
}
else
{
Show();
}
}
}
if (battery.BatteryChargeStatus.ToString() != "NoSystemBattery")
CheckBattery();
title.Text = GetActiveWindowTitle();
time.Text = DateTime.Now.ToString("HH:mm");
if (IsKeyPushedDown(Keys.F7) && helpdialog == false)
{
help.Show();
helpdialog = true;
}
if (IsKeyPushedDown(Keys.F8) && helpdialog == true)
{
helpdialog = false;
help.Hide();
}
if (IsKeyPushedDown(Keys.CapsLock))
{
if (!publicbool.visible)
{
caps.Show();
}
}
Process[] spotify = Process.GetProcessesByName("Spotify");
if (spotify.Length == 0)
{
p_Media.Visible = false;
spotifytrack.Visible = false;
}
else
{
spotifytrack.Text = GetSpotifyTrackInfo();
spotifytrack.Visible = true;
p_Media.Visible = true;
}
}
#endregion
private void p_Forward_Click(object sender, EventArgs e)
{
var KEYEVENTF_KEYUP = 0x0002;
var mediaNextTrack = (byte)Keys.MediaNextTrack;
keybd_event(mediaNextTrack, mediaNextTrack, 0, 0);
keybd_event(mediaNextTrack, mediaNextTrack, KEYEVENTF_KEYUP, 0);
}
private void p_Back_Click(object sender, EventArgs e)
{
var KEYEVENTF_KEYUP = 0x0002;
var mediaPreviousTrack = (byte)Keys.MediaPreviousTrack;
keybd_event(mediaPreviousTrack, mediaPreviousTrack, 0, 0);
keybd_event(mediaPreviousTrack, mediaPreviousTrack, KEYEVENTF_KEYUP, 0);
}
private void btry_MouseHover(object sender, EventArgs e)
{
ttp.Show(battery.BatteryLifePercent.ToString("P0"), btry);
}
private void time_DoubleClick(object sender, EventArgs e)
{
Process.Start("timedate.cpl");
}
private void startbutton_Click(object sender, EventArgs e)
{
byte ctrl = 17;
byte esc = 27;
keybd_event(ctrl, 0, 0, 0);
keybd_event(esc, 0, 0, 0);
keybd_event(ctrl, 0, 2, 0);
keybd_event(esc, 0, 2, 0);
}
private void x1logo_Click(object sender, EventArgs e)
{
byte ctrl = 17;
byte esc = 27;
keybd_event(ctrl, 0, 0, 0);
keybd_event(esc, 0, 0, 0);
keybd_event(ctrl, 0, 2, 0);
keybd_event(esc, 0, 2, 0);
}
}
}