-
Notifications
You must be signed in to change notification settings - Fork 46
/
mDesktop.ahk
4157 lines (3397 loc) · 116 KB
/
mDesktop.ahk
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Author: Jason Stallings
; Contributors: IamTheFij
; Source available http://github.com/octalmage/mDesktop
#NoEnv
#SingleInstance force
SetTitleMatchMode, 2
SetTitleMatchMode, slow
SetWorkingDir, %A_ScriptDir%\
SetBatchLines , -1
SetWinDelay , -1
WinClose, ahk_class SysShadow
#include Win.ahk
onexit , cleanup
;Set this varible here to 0 to turn the gestures off.
gest=0
;These two have to do with the graphic desktop picker.
;Setting this varible to 0 will turn the switcher off.
;Having this on adds about 100% more mem usage. (around 600k to 6000k)
switcher=0
;This is the amount of pixels between each window in the switcher.
spacing=25
;Settings file location.
settings_location=%A_appdata%\mDesktop\
settings_name=settings.ini
settings=%settings_location%%settings_name%
;this is for the new api I'm working on.
api=1
/*
This is for having all windows show up in the taskbar/alt+tab.
This almost works, but is still having some major issues, I believe with the shellhook, and possible my "finddesktop_byid" function.
I need to find a quicker way to detect which desktop a window is on, maybe a new array? So instead of searching I can just do:
desktop:=win_desktop%win_id%
This might work.
*/
taskbar=0
; actual desktop switcher
;DO NOT ENABLE. Not working yet.
desktopswitcher=0
ABM_SETSTATE := 10
ABS_NORMAL := 0x0
ABS_AUTOHIDE := 0x1
ABS_ALWAYSONTOP := 0x2
VarSetCapacity( APPBARDATA , 36, 0 )
Off := NumPut( 36, APPBARDATA )
Off := NumPut( WinExist("ahk_class Shell_TrayWnd"), Off+0 )
;0x00000004 ABM_GETSTATE
rc4key=[insertrc4key]
If switcher
{
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
}
If api
{
hScript := WinExist() + 0
IPC_SetHandler("OnData")
gui 99: default
gui, -caption +toolwindow
gui, show, x0 y0 hide w0 h0,mDesktop_api
gui 1: default
}
numDesktops := 4
gesttime:=800
;TODO: Add code to import settings from swipe.ini.
;Create directory for settings if it doesn't exist.
if !fileexist(settings_location)
{
FileCreateDir, %settings_location%
}
If !fileexist(settings)
{
IniWrite , !^m, %settings%, Settings, unhide
IniWrite , ^#RIGHT, %settings%, Settings, switchnext
IniWrite , ^#LEFT, %settings%, Settings, switchprev
IniWrite , 4, %settings%, Settings, numdesks
IniWrite , !, %settings%, Settings, switchMod
IniWrite , ^!, %settings%, Settings, sendmod
IniWrite , %a_space%, %settings%, Settings, windowsOnAll
IniWrite , 1, %settings%, Settings, desktopcircle
}
IniRead , unhidehotkey, %settings%, Settings, unhide, !^s
IniRead , nexthotkey, %settings%, Settings, switchnext, ^#RIGHT
IniRead , prevhotkey, %settings%, Settings, switchprev, ^#LEFT
IniRead , numDesktops, %settings%, Settings, numdesks, 4
IniRead , switchModifier, %settings%, Settings, switchmod, !
IniRead , sendModifier, %settings%, Settings, sendmod, ^!
IniRead , windowsOnAll, %settings%, Settings, windowsOnAll
IniRead , desktopcircle, %settings%, Settings, desktopcircle
IniRead , theswitchmod, %settings%, Settings, theswitchmod,1
IniRead , thesendmod, %settings%, Settings, thesendmod,1
IniRead , thenextmod, %settings%, Settings, thenextmod,1
IniRead , thepremod, %settings%, Settings, thepremod,1
IniRead , rightaltkey, %settings%, Settings, rightaltkey,1
SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79
SysGet, MonitorCount, MonitorCount
IniRead , runatstartup, %settings%, Settings, runatstartup, 0
Loop %numDesktops%
{
IniRead , desktop%A_Index%, %settings%, Settings, desktop%A_Index%, Desktop %A_Index%
}
Hotkey , %unhidehotkey% , unhide
Hotkey , %unhidehotkey% , off
VarSetCapacity(wallpaper, 260)
DllCall("SystemParametersInfo", "Uint", 115, "Uint", 260, "str", wallpaper, "Uint", 0)
icons=0
curDesktop := 1
;TODO: Allow custom hotkeys.
If switcher
{
Hotkey, f10, switcher
}
gosub buildmenu
PostMessage , 0x111, 28931,,, ahk_class Progman
;Gui 89: -Caption +ToolWindow +LastFound +AlwaysOnTop
;Gui 89: Add, Picture, x0 y0, banner.png
;Gui 89: Add, Text, x15 y5 w70 +BackgroundTrans vString
gosub sethotkeys
;!0::exitapp
PID := DllCall("GetCurrentProcessId")
EmptyMem(pid)
settimer, cleanmem, 450
;settimer, wait, -1
if taskbar
SetTimer, checkactive, 250
GetCurrentWindows(1)
return
ShellMessage( wParam,lParam ) {
critical
If (wParam=5) ; HSHELL_WINDOWCREATED := 1
{
wID := NumGet( lParam+0 ) ; firstmember ( DWord ) of SHELLHOOKINFO structure is hWnd
WinGet, mState, MinMax, ahk_id %wID%
SetFormat, Integer, Hex
; +0 ensures that temp will hold a hex integer value
lParam += 0
wID+=0
switch:= win_desktop%wID%
SetFormat, Integer, D
StringTrimLeft, switch, switch, 2
if not switch
return
SwitchToDesktop(switch)
winactivate, ahk_id %wID%
}
return
}
dec2hex(n) {
oIF := A_FormatInteger
SetFormat,Integer, hex
n := StrLen(n+0) ? n+0 : n
SetFormat,Integer, % oIF
return n
}
OnData(Hwnd, Data, Port, Size) {
IfInString, Data, SwitchToDesktop
{
StringRight, apiDesktop, Data, 1
If apiDesktop is number
SwitchToDesktop(apiDesktop)
}
}
MailslotRead(SlotHandle) ;reads one message at a time
{
global ReadBuffer ;could/should be passed as ByRef parameter
BytesToRead := 500
DLLCall("ReadFile"
,UInt, slotHandle ;the handle from CreateMailSlot
,str , readBuffer ;see AHK DLLCall Help for why str used here
,UInt, BytesToRead
,UIntP, BytesActuallyRead
,UInt, 0) ;pointer to Overlapped structure, not used, so null
If errorlevel
Msgbox Error in ReadFile operation`nErrorLevel: %errorlevel%
Else
return BytesActuallyRead
}
buildmenu:
Ifexist , icons\%curDesktop%.ico
{
If numDesktops <=4
{
Menu, tray ,icon,icons\%curDesktop%o.ico
}
Else{
Menu, tray ,icon,icons\%curDesktop%.ico
}
}
menu ,tray, DeleteAll
menu ,tray, NoStandard
menu ,tray, NoStandard
menu ,tray,add,Hide Icon,hideicon
menu ,tray,add,
menu ,tray,add,About,about
menu ,tray,add,Settings,settings
menu ,tray,add,
Loop %numDesktops%
{
index = %A_Index%
tempDesktop := desktop%A_Index%
If StrLen(tempDesktop) < 1
{
tempDesktop = Desktop %A_Index%
desktop%A_Index% := tempDesktop
}
menu , tray , add , %tempDesktop% , switchMenu
If A_Index = %curDesktop%
{
menu ,tray,Check, %tempDesktop%
}
}
menu ,tray,add,
menu ,tray,add,Exit,CleanUp
return
checkactive:
hwnd := WinExist("A")
WinGetTitle, title , ahk_id %hwnd%
if (hwnd=active)
return
Loop, Parse, windowsOnAll, |,%A_Space%
{
If instr(title,a_loopfield)
{
return
}
}
active:=hwnd
switch:= win_desktop%active%
;msgbox %switch%
if not switch
return
checkactive:=hwnd
SwitchToDesktop(switch)
winactivate, ahk_id %checkactive%
checkactive:=
return
;This was added in to allow the user to click off of the picker, making it goaway.
;Need to find a better way to do this.
/*
~lbutton::
sleep 200
If switchergui
{
return
}
If switcheropen
{
gui 2: destroy
gui 3: destroy
gui 4: destroy
gui 5: destroy
}
return
*/
cleanmem:
EmptyMem(pid)
return
usercanhazaccess(desk)
{
global rc4key
If islocked(desk)
{
InputBox, password, This desktop is locked, Please enter your password:, HIDE, , , , , , 5
iniread, dpassword, %settings%, Settings, passhex
If not Password{
return 0
}
dpassword:= RC4hex2txt(dpassword,rc4key)
If (password=dpassword)
{
return 1
}
Else
{
msgbox Incorrect password!
return 0
}
}
Else
{
return 1
}
}
islocked(desk)
{
IniRead, locked, %settings%, Settings, locked%desk%, 0
return locked
}
sethotkeys:
#MaxThreadsPerHotkey 6
Loop 10
{
If A_Index = 10
index = 0
Else
index = %A_Index%
Hotkey , %switchModifier%%index% , switch
If A_Index <= %numDesktops%
Hotkey , %switchModifier%%index% , on
Else
Hotkey , %switchModifier%%index% , off
}
Hotkey , %nexthotkey% , snext
Hotkey , %prevhotkey% , sprev
#MaxThreadsPerHotkey 1
Loop %numDesktops%
{
If A_Index = 10
index = 0
Else
index = %A_Index%
Hotkey , ~%sendModifier%%index% , sendTo
If A_Index <= %numDesktops%
Hotkey , ~%sendModifier%%index% , on
Else
Hotkey , ~%sendModifier%%index% , off
}
return
hideicon:
menu ,tray,NoIcon
Hotkey , %unhidehotkey% , on
StringReplace , DisplayKey, unhidehotkey, ^ , Control%a_space% , All
StringReplace , DisplayKey, DisplayKey, ! , Alt%a_space% , All
StringReplace , DisplayKey, DisplayKey, + ,Shift%a_space% , All
msgbox The icon will now be hidden, press %DisplayKey% to unhide.
return
unhide:
menu ,tray,Icon
Hotkey , %unhidehotkey% , off
return
switch:
if (rightaltkey)
{
If getkeystate("ralt")
{
return
}
}
length := StrLen(A_ThisHotkey) - 1
theDesk := SubStr(A_ThisHotkey, %length%)
If theDesk = 0
theDesk = 10
SwitchToDesktop(theDesk)
return
sendTo:
If getkeystate("ralt")
{
return
}
length := StrLen(A_ThisHotkey) - 1
theDesk := SubStr(A_ThisHotkey, %length%)
If theDesk = 0
theDesk = 10
SendActiveToDesktop(theDesk, curDesktop)
return
switchMenu:
theDesk := A_ThisMenuItemPos - 5
SwitchToDesktop(theDesk)
return
snext:
SwitchToNextDesktop()
return
sprev:
SwitchToPrevDesktop()
return
settings:
Hotkey , %nexthotkey% , off
Hotkey , %prevhotkey% , off
ctrlKey = ^
altKey = !
winKey = #
shiftKey = +
Gui 7: Add, Tab2,h400, General|Desktop Names|Windows
Gui 7: Tab, 1
; Number of Desktops
gui 7: add,text,,Number of Desktops (Max 10):
gui 7: add,edit,w25 number vnewnumdesktops, %numDesktops%
;gui 7: add,updown, Range1-10 vnewnumdesktops, %numDesktops%
; Hide Tray icon
gui 7: add,text,,Select a hotkey to unhide mDesktop's tray icon.
gui 7: add,hotkey,vnewunhidehotkey, %unhidehotkey%
Gui 7: Tab, 1
; Modifiers for switch desktop
gui 7: add,text,,To switch directly to a desktop:
gui, 7: Tab, 1
gui, 7: add, DropDownList ,w150 Choose%theswitchmod% vtheswitchmod altsubmit, Alt+Desktop Number|Ctrl+Desktop Number|Shift+Desktop Number|
gui, 7: add, CheckBox,vrightaltkey checked%rightaltkey%, Ignore right alt key?
gui, 7: add,text, yp+25 xm+12 ,To send an active window to a desktop:
gui, 7: add, DropDownList,Choose%thesendmod% vthesendmod w150 altsubmit , Alt+Ctrl+Desktop Number|Shift+Alt+Desktop Number|Ctrl+Shift+Desktop Number|
; Switch Next Hotkeys
nexthaswin=UnChecked
If InStr(nexthotkey, winKey)
{
nexthaswin=Checked
StringReplace , cleannexthotkey, nexthotkey, # , , All
}
Else
{
cleannexthotkey := nexthotkey
}
gui 7: add,text,xm+12 yp+25 ,To switch to the next desktop:
Gui 7: Add, DropDownList,altsubmit vthenextmod Choose%thenextmod% w150, Ctrl+Right Arrow|Shift+Right Arrow|Alt+Right Arrow|
; Switch Prev Hotkeys
prevhaswin=UnChecked
If InStr(prevhotkey, winKey)
{
prevhaswin=Checked
StringReplace , cleanprevhotkey, prevhotkey, # , , All
}
Else
{
cleanprevhotkey := prevhotkey
}
gui 7: add,text,xm+12 yp+25 ,To switch to the previous desktop:
Gui 7: Add, DropDownList, vthepremod w150 altsubmit Choose%thepremod%, Ctrl+Left Arrow|Shift+Left Arrow|Alt+Left Arrow|
If runatstartup
{
gui 7: add,checkbox,vrunatstartup checked, Run at Startup?
}
Else
{
gui 7: add,checkbox,vrunatstartup, Run at Startup?
}
If desktopcircle
{
gui 7: add,checkbox,vdesktopcircle checked, Desktop Cycling
}
Else
{
gui 7: add,checkbox,vdesktopcircle, Desktop Cycling
}
Gui 7: Tab, 2
; Desktop Names
gui 7: add,text,ym+26 xm+12,Name your desktops.
namex=25
namey=52
locky:=52+4
lockx=128
Loop %numDesktops%
{
tempDesktop := desktop%A_Index%
gui 7: add,edit,w100 x%namex% y%namey% vnewdesktop%A_Index% , %tempDesktop%
namey+=25
}
/*
Loop %numDesktops%
{
If % locked%A_Index%
{
gui 7: add,Checkbox,y%locky% checked x%lockx% vlocked%A_Index%, Locked
}
Else
{
gui 7: add,Checkbox,y%locky% x%lockx% vlocked%A_Index%, Locked
}
locky+=25
}
namey:=namey+10
;Password Section
gui 7: add,text,x%namex% y%namey%,Desktop Passowrd:
namey+=20
gui 7: add,edit,x%namex% w100 password y%namey% center vdpassword, mdesktopwins
*/
Gui 7: Tab, 3
;Windows on all desktops
Gui 7: Add, Text,,Windows on all desktops
Gui 7: Add, ListView, -multi vwindowlist, Title
Gui 7: Add, Button,gadd_window, Add
Gui 7: Add, Button,yp xp+35 gselect, Select
Gui 7: Add, Button,yp xp+46 gwindow_delete, Delete
Gui 7: Tab, 1
Gui 7: Tab,
ControlGetPos , xx, yy, , hh, SysTabControl321,Settings
buttony:=yy+hh+400
gui 7: add,button, y418 x10 gsavesettings,Save
gui +lastfound
gui 7: show,, Settings
settingid:=WinExist()
gui 7: default
Loop, Parse, windowsOnAll, |,%A_Space%
{
LV_Add("", a_loopfield)
}
gui 1: default
return
7guiclose:
Hotkey, %nexthotkey% , on
Hotkey, %prevhotkey% , on
gui 7: destroy
return
select:
sleep 100
gui 97: default
gui, -caption +toolwindow +alwaysontop
gui,color,red
gui, Add,text,,Please click a window to add to the list.
gui,show,x25 y25
KeyWait, lbutton,d
wingetactivetitle, activetitle
If not activetitle
return
gui 7: default
LV_Add("", activetitle)
gui 1: default
gui 97: destroy
WinActivate , ahk_id %settingid%
activetitle=
return
window_delete:
row:=LV_GetNext()
LV_Delete(row)
return
savesettings:
gui 7: submit
; Save window on all desktops section.
windowsOnAll=
count:=LV_GetCount()
Loop %count%
{
LV_GetText(RetrievedTitle, A_Index)
windowsOnAll=%RetrievedTitle%|%windowsOnAll%
}
StringTrimRight, windowsonall, windowsonall, 1
IniWrite , %windowsonall%, %settings%, Settings, windowsOnAll
gui 7: destroy
IniWrite , %theswitchmod%, %settings%, settings, theswitchmod
IniWrite , %thesendmod%, %settings%, settings, thesendmod
IniWrite , %thenextmod%, %settings%, settings, thenextmod
IniWrite , %thepremod%, %settings%, settings, thepremod
IniWrite , %rightaltkey%, %settings%, settings, rightaltkey
if (thenextmod=1)
{
newnexthotkey=^RIght
}
else if (thenextmod=2)
{
newnexthotkey=+RIght
}
else if (thenextmod=3)
{
newnexthotkey=!RIght
}
if (thepremod=1)
{
newprevhotkey=^Left
}
else if (thepremod=2)
{
newprevhotkey=+Left
}
else if (thepremod=3)
{
newprevhotkey=!Left
}
; Set Switch Desktop Modifiers
if (theswitchmod=1)
{
newSwitchModifier=!
}
else if (theswitchmod=2)
{
newSwitchModifier=^
}
else if (theswitchmod=3)
{
newSwitchModifier=+
}
If newSwitchModifier != %switchModifier%
{
Loop 10
{
If A_Index = 10
index = 0
Else
index = %A_Index%
Hotkey , %switchModifier%%index% , off
}
switchModifier := newSwitchModifier
IniWrite , %switchModifier%, %settings%, Settings, switchmod
}
; Set Send to Desktop Modifiers
if (thesendmod=1)
{
newSendModifier=!^
}
else if (thesendmod=2)
{
newSendModifier=+!
}
else if (thesendmod=3)
{
newSendModifier=^+
}
If newSendModifier != %SendModifier%
{
sendModifier := newSendModifier
IniWrite , %sendModifier%, %settings%, Settings, sendmod
}
; Save unhide hotkey
If newunhidehotkey!= %unhidehotkey%
{
Hotkey , %newunhidehotkey% , unhide
Hotkey , %newunhidehotkey% , off
unhidehotkey= %newunhidehotkey%
IniWrite , %unhidehotkey%, %settings%, settings, unhide
}
; Rename desktops
Loop %numDesktops%
{
newDesktop := newdesktop%A_Index%
oldDesktop := desktop%A_Index%
If newDesktop != %oldDesktop%
{
menu , tray, rename, %oldDesktop%, %newDesktop%
desktop%A_Index% := newDesktop
IniWrite , %newDesktop%, %settings%, Settings, desktop%A_Index%
}
}
; Set number of desktops
If newnumdesktops > 10
newnumdesktops := 10
If newnumdesktops < 1
newnumdesktops := 1
If newnumdesktops != %numDesktops%
{
If newnumdesktops < %numDesktops%
{
If curDesktop > %newnumdesktops%
SwitchToDesktop(newnumdesktops)
index := (numDesktops - newnumdesktops)
Loop , %index%
{
theDesk := numDesktops - A_Index + 1
MoveAllWindows(theDesk, curDesktop)
}
}
numDesktops = %newnumdesktops%
IniWrite , %numDesktops%, %settings%, Settings , numdesks
menu , tray , deleteall
gosub buildmenu
}
If newnexthotkey!= %nexthotkey%
{
nexthotkey = %newnexthotkey%
Hotkey , %nexthotkey% , snext
IniWrite , %nexthotkey%, %settings%, settings, switchnext
}
If newprevhotkey!=%prevhotkey%
{
prevhotkey = %newprevhotkey%
Hotkey , %prevhotkey% , sprev
IniWrite , %prevhotkey%, %settings%, settings, switchprev
}
; Save run at startup
If runatstartup=1
{
RegWrite, REG_SZ,HKCU,Software\Microsoft\Windows\CurrentVersion\Run,mDesktop, "%A_ScriptFullPath%"
}
Else
{
RegDelete, HKCU,Software\Microsoft\Windows\CurrentVersion\Run,mDesktop
}
iniwrite, %runatstartup%, %settings%, Settings, runatstartup
iniwrite, %desktopcircle%, %settings%, Settings, desktopcircle
Hotkey, %nexthotkey% , on
Hotkey, %prevhotkey% , on
gosub sethotkeys
return
add_window:
InputBox, window , Add a window, Please type in part of the window title you would like to remain on all desktops.
If not window
return
LV_Add("", window)
window=
return
SwitchToNextDesktop()
{
global
If (curDesktop < numDesktops)
{
SwitchToDesktop(curDesktop + 1)
}
Else
{
If desktopcircle
SwitchToDesktop(1)
}
return
}
SwitchToPrevDesktop()
{
global
If (curDesktop > 1)
{
SwitchToDesktop(curDesktop - 1)
}
Else
{
If desktopcircle
SwitchToDesktop(numDesktops)
}
return
}
CheckDesktop(newDesktop)
{
global
Loop %numDesktops%
{
tempDesktop := desktop%A_Index%
If newDesktop = %A_Index%
menu ,tray,Check, %tempDesktop%
Else
menu ,tray,Uncheck, %tempDesktop%
}
return
}
SwitchToDesktop(newDesktop)
{
global
activate_window :=
If not usercanhazaccess(newDesktop)
{
return
}
Loop %numDesktops%
{
If A_Index = 10
index = 0
Else
index = %A_Index%
Hotkey , %switchModifier%%index% , off
}
If (curDesktop <> newDesktop)
{
;pBitmap%curDesktop% := Gdip_BitmapFromScreen(0)
;sc_CaptureScreen(0, false, curDesktop . ".jpg", "20")
CheckDesktop(newDesktop)
GetCurrentWindows(curDesktop)
WinGet, aid, ID, A
if not (checkactive)
{
if not aid
active_id%curDesktop%:=winexist("Program Manager")