Skip to content

Commit cea44a2

Browse files
committed
set where to show the launcher
1 parent 6a2a635 commit cea44a2

File tree

4 files changed

+135
-11
lines changed

4 files changed

+135
-11
lines changed

ahko.ahk

+16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@ Persistent
55
path:=IniRead("setting.ini", "dir", "path", "")
66
hotkeys:=IniRead("setting.ini", "hotkey", "key", "!q")
77
fullscreen_enable:=IniRead("setting.ini", "hotkey", "fullscreen", "0")
8+
uiType_list:="1|2"
89
uiType:=IniRead("setting.ini", "ui", "type", "2")
10+
if not RegExMatch(uiType, uiType_list)
11+
{
12+
uiType := "2"
13+
}
14+
; 0 = primary monitor
15+
; 1~9 = specific monitor
16+
; 10 = monitor the mouse at
17+
; 11 = monitor the activate window at
18+
showat_list:="0|1|2|3|4|5|6|7|8|9|10|11"
19+
showat:=IniRead("setting.ini", "settings", "showat", "10")
20+
if not RegExMatch(showat, showat_list)
21+
{
22+
showat := "10"
23+
}
924

1025
#include isFullScreen.ahk
1126
#include ahko_setup_gui.ahk
@@ -93,6 +108,7 @@ isNotFullScreen(*)
93108

94109
#Include ahko_ui.ahk
95110
ahko_ui_init()
111+
; TODO: if hotkey invalid, then reset the hotkey to default
96112
if(fullscreen_enable)
97113
{
98114
Hotkey hotkeys, ahko_show, "On"

ahko_gridview_ui.ahk

+47-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ahko_gridview_init(ahko)
1818
local outerIndex:=1
1919
local gmargin:=10
2020
local titleHeight:=40
21+
ahko_grid.size:={w:5.5*(buttonSize+gmargin), h:4*(buttonSize+gmargin)+titleHeight}
2122

2223
gridview_presetup(ahko_grid)
2324
ahko_grid.add("Button", "w" buttonSize " h" titleHeight " x0 y1 left", " ahko")
@@ -83,7 +84,7 @@ gui_user_bind(g)
8384
}
8485
uShow(*) {
8586
g.isHide:=False
86-
g.Show()
87+
g.Show(grid_showat())
8788
}
8889
g.btnCall:=[]
8990
g.isHide:=True
@@ -131,6 +132,51 @@ gridview_postsetup(grid)
131132
grid.BackColor := "FF00FF"
132133
WinSetTransColor "FF00FF 0xE0", grid.Hwnd
133134
grid.Opt("-Caption")
135+
grid.Show("Hide")
136+
}
137+
138+
grid_showat()
139+
{
140+
global showat,ahko_grid,isFullScreen
141+
; MsgBox(showat)
142+
CoordMode("Mouse","Screen")
143+
if(showat=="0"){
144+
Return ""
145+
}
146+
if(showat>=1 and showat<=9){
147+
if(isFullScreen.monitors.Length >= showat){
148+
Return showat_monitor(showat)
149+
}else{
150+
Return ""
151+
}
152+
}
153+
if(showat=="10"){
154+
MouseGetPos(&mx,&my)
155+
For k, v in isFullScreen.monitors
156+
{
157+
; MsgBox("m" k ":mx" mx ",my" my "`nl" v.l "r" v.r "t" v.t "b" v.b)
158+
if(mx>=v.l && mx<=v.r && my>=v.t && my<=v.b){
159+
Return showat_monitor(k)
160+
}
161+
}
162+
}
163+
if(showat=="11"){
164+
WinGetPos(&wx, &wy, &ww, &wh, "A")
165+
wx+=ww//3
166+
wy+=wh//3
167+
For k, v in isFullScreen.monitors
168+
{
169+
if(wx>=v.l and wx<=v.r and wy>=v.t and wy<=v.b){
170+
Return showat_monitor(k)
171+
}
172+
}
173+
}
174+
Return ""
175+
showat_monitor(n){
176+
; MsgBox("showat " n)
177+
; ahko_grid.GetClientPos(,,&w,&h)
178+
Return "x" Round(isFullScreen.monitors[n].l+isFullScreen.monitors[n].r-ahko_grid.size.w)//2 " y" Round(isFullScreen.monitors[n].t+isFullScreen.monitors[n].b-ahko_grid.size.h)//2
179+
}
134180
}
135181

136182
;{ GuiButtonIcon

ahko_setup_gui.ahk

+70-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
h2FontStyle:="s22 w600 c505050 q5"
44
textFontStyle:="s12 w400 cblack q5"
55
clientWidth:=320
6+
header_gap:=" y+20 "
7+
item_gap:=" y+5 "
68

79
ahko_setup := Gui("+ToolWindow +AlwaysOnTop -DPIScale +OwnDialogs","ahko setup")
810
ahko_setup.SetFont(, "Microsoft JhengHei")
@@ -18,7 +20,7 @@ ahko_setup.Add("Text", "x0 y+-50 +BackgroundTrans", "____________________")
1820
ahko_setup.SetFont(h2FontStyle)
1921
ahko_setup.Add("Text","x30 y+20 section", "UI type")
2022
ahko_setup.SetFont(textFontStyle)
21-
ahkoSetup_uiType:=ahko_setup.Add("DropDownList", "y+10 w" clientWidth, ["Listview","Gridview","Gridview(Gdip)"])
23+
ahkoSetup_uiType:=ahko_setup.Add("DropDownList", item_gap "w" clientWidth, ["Listview(Deprecated)","Gridview","Gridview(Gdip)"])
2224
ahkoSetup_uiType.OnEvent("Change", uiType_update)
2325
uiType_update(*) {
2426
if(ahkoSetup_uiType.Value>2) {
@@ -27,10 +29,10 @@ uiType_update(*) {
2729
}
2830
}
2931
ahko_setup.SetFont(h2FontStyle)
30-
ahko_setup.Add("Text", "xs y+30", "Watch folder")
32+
ahko_setup.Add("Text", "xs " header_gap, "Watch folder")
3133
ahko_setup.SetFont(textFontStyle)
3234
buttonWidth:=95
33-
AhkoSetup_path:=ahko_setup.Add("Edit", "y+10 r1 w" clientWidth-buttonWidth-5, "")
35+
AhkoSetup_path:=ahko_setup.Add("Edit", item_gap "r1 w" clientWidth-buttonWidth-5, "")
3436
pathSelectBtn := ahko_setup.Add("Button", "x+5 hp w" buttonWidth, "Select")
3537
pathSelectBtn.OnEvent("Click", setup_path)
3638
setup_path(*){
@@ -41,24 +43,81 @@ setup_path(*){
4143
}
4244

4345
ahko_setup.SetFont(h2FontStyle)
44-
ahko_setup.Add("Text", "xs y+30", "Hotkey")
46+
ahko_setup.Add("Text", "xs " header_gap, "Hotkey")
4547
ahko_setup.SetFont(textFontStyle)
46-
ahkoSetup_hotkey:=ahko_setup.Add("Hotkey", "y+10 w" clientWidth-buttonWidth-5)
48+
ahkoSetup_hotkey:=ahko_setup.Add("Hotkey", item_gap "w" clientWidth-buttonWidth-5)
4749
ahkoSetup_hotkey.OnEvent("Change", hotkeyText_update)
4850
ahkoSetup_hotkeyWin:=ahko_setup.Add("CheckBox", "x+10 hp w" buttonWidth, "Win")
4951
ahkoSetup_hotkeyWin.OnEvent("Click", hotkeyText_update)
5052

5153
ahko_setup.SetFont("s10")
52-
ahko_setup.Add("Text", "xs y+5", "Hotkey is ")
54+
ahko_setup.Add("Text", "xs" item_gap, "Hotkey is ")
5355
ahkoSetup_hotkeyText:=ahko_setup.Add("Text", "x+0 hp cc07070 w260", "")
5456

5557
ahko_setup.SetFont(h2FontStyle)
56-
ahko_setup.Add("Text", "xs y+30", "Other")
58+
ahko_setup.Add("Text", "xs " header_gap, "ahko where")
5759
ahko_setup.SetFont(textFontStyle)
58-
ahkoSetup_enable_fullscreen:=ahko_setup.Add("CheckBox", "y+10 hp", "Enable in fullscreen")
60+
showAtDDL:=["Primary monitor","Follow mouse","Follow active window"]
61+
For k, v in isFullScreen.monitors
62+
{
63+
showAtDDL.Push("Monitor #" k)
64+
}
65+
ahkoSetup_showAt:=ahko_setup.Add("DropDownList", item_gap "w" clientWidth, showAtDDL)
66+
ahkoSetup_showAt.OnEvent("Change", showAt_update)
67+
showat_from_ddl(dd) {
68+
if(dd>=4) {
69+
return dd-3
70+
} else if(dd>=1) {
71+
if(dd == 1) {
72+
return 0
73+
}
74+
if(dd == 2) {
75+
return 10
76+
}
77+
if(dd == 3) {
78+
return 11
79+
}
80+
}
81+
return 1
82+
}
83+
ddl_from_showat(sw) {
84+
if(sw==0) {
85+
return 1
86+
}
87+
if(sw==10) {
88+
return 2
89+
}
90+
if(sw==11){
91+
return 3
92+
}
93+
if(sw>=1 && sw<=9){
94+
return sw+3
95+
}
96+
return 1
97+
}
98+
showAt_update(*) {
99+
global showat
100+
; MsgBox(ahkoSetup_showAt.Value)
101+
if(ahkoSetup_showAt.Value>=4) {
102+
showat:=showat_from_ddl(ahkoSetup_showAt.Value)
103+
ahko_setup.Show(showat_monitor(showat))
104+
} else {
105+
showat:=showat_from_ddl(ahkoSetup_showAt.Value)
106+
}
107+
showat_monitor(n){
108+
global isFullScreen, ahko_setup
109+
ahko_setup.GetClientPos(,,&w,&h)
110+
Return "x" Round(isFullScreen.monitors[n].l+isFullScreen.monitors[n].r-w)//2 " y" Round(isFullScreen.monitors[n].t+isFullScreen.monitors[n].b-h)//2
111+
}
112+
}
113+
114+
ahko_setup.SetFont(h2FontStyle)
115+
ahko_setup.Add("Text", "xs " header_gap, "Other")
116+
ahko_setup.SetFont(textFontStyle)
117+
ahkoSetup_enable_fullscreen:=ahko_setup.Add("CheckBox", item_gap "hp", "Enable in fullscreen")
59118
ahkoSetup_enable_fullscreen.OnEvent("Click", enable_fullscreen_update)
60119

61-
ahkoSetup_autoStart:=ahko_setup.Add("CheckBox", "y+5 hp", "Startup with Windows")
120+
ahkoSetup_autoStart:=ahko_setup.Add("CheckBox", "y+0 hp", "Startup with Windows")
62121
ahkoSetup_autoStart.OnEvent("Click", autoStartup_update)
63122

64123
ahko_setup.SetFont(textFontStyle)
@@ -91,6 +150,7 @@ hotkeyText_update(*) {
91150
ahko_setup_show(*) {
92151
global
93152
ahkoSetup_uiType.Value:=uiType
153+
ahkoSetup_showAt.Value:=ddl_from_showat(showat)
94154
ahkoSetup_path.Value:=path
95155

96156
ahkoSetup_hotkey.Value:=RegExReplace(hotkeys, "#")
@@ -124,6 +184,7 @@ ahko_setup_save(*) {
124184
IniWrite("key=" hotkeyStr, "setting.ini", "hotkey")
125185
IniWrite("fullscreen=" fullscreen_enable, "setting.ini", "hotkey")
126186
IniWrite("type=" ahkoSetup_uiType.Value, "setting.ini", "ui")
187+
IniWrite("showat=" showat, "setting.ini", "settings")
127188
MsgBox("In order for the changes to take effect`nahko is is about to be restarted","OK","Owner" ahko_setup.Hwnd)
128189
Reload
129190
}

meta.ahk

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
FileEncoding("UTF-8")
33
appName:="ahko"
4-
version:="0.2.3"
4+
version:="0.2.4"
55
versionFilename:="version.txt"
66
ahkFilename:="app.ahk"
77
binaryFilename:="ahko.exe"
@@ -11,5 +11,6 @@ update_log:="
1111
(
1212

1313
1. Now you can disable hotkey in fullscreen
14+
2. Now you can select where to show the launcher
1415

1516
)"

0 commit comments

Comments
 (0)