-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowLayoutEngine.Generators.iss
More file actions
648 lines (529 loc) · 18 KB
/
WindowLayoutEngine.Generators.iss
File metadata and controls
648 lines (529 loc) · 18 KB
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
objectdef windowLayoutGenerator
{
variable string Name="Unnamed Window Layout"
variable string Description="Fails to generate a Window Layout"
member:jsonvalueref GenerateRegions(jsonvalueref joInput)
{
return NULL
}
member ToText()
{
return "${Name~}"
}
}
objectdef windowLayoutGenerators
{
variable windowLayoutGenerator_Edge Edge
variable windowLayoutGenerator_Stacked Stacked
variable windowLayoutGenerator_ScreenPer ScreenPer
variable windowLayoutGenerator_Tile Tile
variable windowLayoutGenerator_Grid Grid
variable windowLayoutGenerator_Combo Combo
variable collection:weakref Generators
method Initialize()
{
Generators:Set["${Edge~}",Edge]
Generators:Set["${Stacked~}",Stacked]
Generators:Set["${ScreenPer~}",ScreenPer]
Generators:Set["${Tile~}",Tile]
Generators:Set["${Grid~}",Grid]
; Generators:Set["${Horizontal~}",Horizontal]
; Generators:Set["${Vertical~}",Vertical]
}
member:weakref GetGenerator(string name)
{
return "This.Generators.Get[${name~}]"
}
}
/*
input
{
"numSlots":5,
"useMonitor":1,
"monitors":[
{
"id":0,
"name":"\\\\.\\DISPLAY609",
"primary":true,"left":0,"right":1920,"top":0,"bottom":1080,"width":1920,"height":1080,
"maximizeLeft":0,"maximizeRight":1920,"maximizeTop":0,"maximizeBottom":1040,"maximizeWidth":1920,"maximizeHeight":1040
}
],
"avoidTaskbar":false,
"leaveHole":true
}
output:
[
{"mainRegion":true,"x":0,"y":0,"width":1920,"height":900},
{"x":0,"y":900,"width":384,"height":180},
{"x":384,"y":900,"width":384,"height":180},
{"x":768,"y":900,"width":384,"height":180},
{"x":1152,"y":900,"width":384,"height":180},
{"x":1536,"y":900,"width":384,"height":180}
]
*/
objectdef windowLayoutGenerator_Common inherits windowLayoutGenerator
{
variable uint numSlots
variable uint useMonitor
variable uint numInactiveRegions
variable jsonvalueref joMonitor
variable uint monitorWidth
variable uint monitorHeight
variable int monitorX
variable int monitorY
member:jsonvalueref GenerateRegions_Subclass(jsonvalueref joInput)
{
return NULL
}
member:jsonvalueref GenerateRegions(jsonvalueref joInput)
{
variable jsonvalue ja
useMonitor:Set[${joInput.GetInteger[useMonitor]}]
if !${useMonitor}
useMonitor:Set[1]
joMonitor:SetReference["joInput.Get[monitors,${useMonitor}]"]
if !${joMonitor.Reference(exists)}
return NULL
numInactiveRegions:Set[${joInput.GetInteger[numInactiveRegions]}]
numSlots:Set[${joInput.GetInteger[numSlots]}]
if !${numSlots}
numSlots:Set[1]
; echo monitor=${joMonitor~} width=${joMonitor.GetNumber[width]}
if !${numInactiveRegions}
numInactiveRegions:Set[${numSlots}]
if ${joInput.GetBool[avoidTaskbar]}
{
monitorX:Set["${joMonitor.GetNumber[maximizeLeft]}"]
monitorY:Set["${joMonitor.GetNumber[maximizeTop]}"]
monitorWidth:Set["${joMonitor.GetNumber[maximizeWidth]}"]
monitorHeight:Set["${joMonitor.GetNumber[maximizeHeight]}"]
}
else
{
monitorX:Set["${joMonitor.GetNumber[left]}"]
monitorY:Set["${joMonitor.GetNumber[top]}"]
monitorWidth:Set["${joMonitor.GetNumber[width]}"]
monitorHeight:Set["${joMonitor.GetNumber[height]}"]
}
; if there's only 1 window, just go full screen windowed
if ${numSlots}==1
{
ja:SetValue["$$>
[
{
"mainRegion":true,
"x":${monitorX},
"y":${monitorY},
"width":${monitorWidth},
"height":${monitorHeight},
"numRegion":1
}
]
<$$"]
return ja
}
return "This.GenerateRegions_Subclass[joInput]"
}
}
objectdef windowLayoutGenerator_Combo inherits windowLayoutGenerator
{
method Initialize()
{
Name:Set[Combo]
Description:Set["Generates a layout composed of multiple other layouts! Layoutception."]
}
method AddLayout(uint numLayout, jsonvalueref ja, jsonvalueref joCombo, jsonvalueref joInput)
{
; echo "Combo:AddLayout ${joInput.Type} ${joInput~}"
variable weakref wlGenerator
wlGenerator:SetReference["WLEngine.Generators.GetGenerator[\"${joInput.Get[generator]~}\"]"]
variable jsonvalue joMerged="${joCombo~}"
joMerged:Erase[layouts]
joMerged:Merge[joInput]
; echo "merged=${joMerged~}"
variable jsonvalue jaRegions
jaRegions:SetValue["${wlGenerator.GenerateRegions["joMerged"]~}"]
jaRegions:ForEach["ForEach.Value:SetInteger[numLayout,${numLayout}]"]
; echo "result=${jaRegions~}"
if ${jaRegions.Type~.Equal[Array]}
{
jaRegions:ForEach["ja:AddByRef[ForEach.Value]"]
}
}
member:jsonvalueref GenerateRegions(jsonvalueref joInput)
{
variable jsonvalue ja="[]"
variable uint numLayout
variable jsonvalueref joLayout
; echo "Combo:GenerateRegions ${joInput~}"
joInput.Get[layouts]:ForEach["This:AddLayout[\${ForEach.Key},ja,joInput,ForEach.Value]"]
; echo "Combo:GenerateRegions result=${ja~}"
return ja
}
}
objectdef windowLayoutGenerator_ScreenPer inherits windowLayoutGenerator
{
method Initialize()
{
Name:Set[ScreenPer]
Description:Set["Generates a layout where each window is assigned to its own monitor (reusing monitors if there's too many characters)"]
}
member:jsonvalueref GenerateForScreen(jsonvalueref joInput, uint numMonitor, bool mainRegion)
{
variable jsonvalue joRegion
variable bool avoidTaskbar=${joInput.GetBool[avoidTaskbar]}
variable jsonvalueref joMonitor
variable uint monitorWidth
variable uint monitorHeight
variable int monitorX
variable int monitorY
joMonitor:SetReference["joInput.Get[monitors,${numMonitor}]"]
if !${joMonitor.Reference(exists)}
return NULL
if ${avoidTaskbar}
{
monitorX:Set["${joMonitor.GetNumber[maximizeLeft]}"]
monitorY:Set["${joMonitor.GetNumber[maximizeTop]}"]
monitorWidth:Set["${joMonitor.GetNumber[maximizeWidth]}"]
monitorHeight:Set["${joMonitor.GetNumber[maximizeHeight]}"]
}
else
{
monitorX:Set["${joMonitor.GetNumber[left]}"]
monitorY:Set["${joMonitor.GetNumber[top]}"]
monitorWidth:Set["${joMonitor.GetNumber[width]}"]
monitorHeight:Set["${joMonitor.GetNumber[height]}"]
}
joRegion:SetValue["$$>
{
"x":${monitorX},
"y":${monitorY},
"width":${monitorWidth},
"height":${monitorHeight}
}
<$$"]
if ${mainRegion}
joRegion:SetBool[mainRegion,1]
return joRegion
}
member:jsonvalueref GenerateRegions(jsonvalueref joInput)
{
variable jsonvalue ja=[]
variable uint numMonitors=${joInput.Get[monitors].Used}
variable uint numInactiveRegions=${joInput.GetInteger[numInactiveRegions]}
variable uint numSlots=${joInput.GetInteger[numSlots]}
if !${numSlots}
numSlots:Set[1]
if !${numInactiveRegions}
numInactiveRegions:Set[${numSlots}-1]
numSlots:Set[${numInactiveRegions}+1]
variable uint numSlot
variable jsonvalue joRegion
variable bool mainRegion=1
variable uint useMonitor
for (numSlot:Set[1] ; ${numSlot}<=${numSlots} ; numSlot:Inc)
{
useMonitor:Set[(${numSlot.Dec}%${numMonitors})+1]
joRegion:SetValue["${This.GenerateForScreen[joInput,${useMonitor},${mainRegion}]~}"]
joRegion:SetInteger["numRegion",${numSlot}]
ja:Add["${joRegion~}"]
mainRegion:Set[0]
}
return ja
}
}
objectdef windowLayoutGenerator_Stacked inherits windowLayoutGenerator_Common
{
method Initialize()
{
Name:Set[Stacked]
Description:Set["Generates a layout where all windows are stacked on top of each other in the same place (for example, full screen)"]
}
member:jsonvalueref GenerateRegions_Subclass(jsonvalueref joInput)
{
variable jsonvalue ja="[]"
variable jsonvalue joRegion
; main region
joRegion:SetValue["$$>
{
"mainRegion":true,
"x":${monitorX},
"y":${monitorY},
"width":${monitorWidth},
"height":${monitorHeight},
"numRegion":1
}
<$$"]
ja:Add["${joRegion~}"]
variable uint numSlot
joRegion:SetValue["$$>
{
"x":${monitorX},
"y":${monitorY},
"width":${monitorWidth},
"height":${monitorHeight}
}
<$$"]
for (numSlot:Set[1] ; ${numSlot}<=${numInactiveRegions} ; numSlot:Inc)
{
joRegion:SetInteger[numRegion,${numSlot.Inc}]
ja:Add["${joRegion~}"]
}
return ja
}
}
objectdef windowLayoutGenerator_Edge inherits windowLayoutGenerator_Common
{
method Initialize()
{
Name:Set[Edge]
Description:Set["Generates a standard layout with small regions along an edge of the screen"]
}
member:jsonvalueref GenerateRegions_Subclass(jsonvalueref joInput)
{
switch ${joInput.Get[edge]~}
{
case left
case right
return "This.GenerateRegions_Vertical[joInput]"
case top
case bottom
return "This.GenerateRegions_Horizontal[joInput]"
}
}
member:jsonvalueref GenerateRegions_Horizontal(jsonvalueref joInput)
{
variable jsonvalue ja="[]"
variable jsonvalue joRegion
variable uint mainHeight
variable uint mainWidth
variable uint smallHeight
variable uint smallWidth
variable bool useBottom=${joInput.Get[edge]~.NotEqual[top]}
if !${joInput.GetBool[leaveHole]} && !${joInput.Has[numInactiveRegions]}
numInactiveRegions:Dec
; 2 windows is actually a 50/50 split screen and should probably handle differently..., pretend there's 3
if ${numInactiveRegions}<3
numInactiveRegions:Set[3]
mainWidth:Set["${monitorWidth}"]
mainHeight:Set["${monitorHeight}*${numInactiveRegions}/(${numInactiveRegions}+1)"]
smallHeight:Set["${monitorHeight}-${mainHeight}"]
smallWidth:Set["${monitorWidth}/${numInactiveRegions}"]
variable int useY=${monitorY}
if !${useBottom}
useY:Set[${monitorY}+${smallHeight}]
; main region
joRegion:SetValue["$$>
{
"mainRegion":true,
"x":${monitorX},
"y":${useY},
"width":${mainWidth},
"height":${mainHeight},
"numRegion":1
}
<$$"]
ja:Add["${joRegion~}"]
variable int useX=${monitorX}
variable uint numSlot
useY:Set[${mainHeight}+${monitorY}]
if !${useBottom}
{
useY:Set[${monitorY}]
}
joRegion:SetValue["$$>
{
"x":${useX},
"y":${useY},
"width":${smallWidth},
"height":${smallHeight}
}
<$$"]
for (numSlot:Set[1] ; ${numSlot}<=${numInactiveRegions} ; numSlot:Inc)
{
joRegion:SetInteger[x,${useX}]
joRegion:SetInteger[numRegion,${numSlot.Inc}]
ja:Add["${joRegion~}"]
useX:Inc["${smallWidth}"]
}
return ja
}
member:jsonvalueref GenerateRegions_Vertical(jsonvalueref joInput)
{
variable jsonvalue ja="[]"
variable jsonvalue joRegion
variable uint mainHeight
variable uint mainWidth
variable uint smallHeight
variable uint smallWidth
variable bool useRight=${joInput.Get[edge]~.NotEqual[left]}
if !${joInput.GetBool[leaveHole]} && !${joInput.Has[numInactiveRegions]}
numInactiveRegions:Dec
; 2 windows is actually a 50/50 split screen and should probably handle differently..., pretend there's 3
if ${numInactiveRegions}<3
numInactiveRegions:Set[3]
mainHeight:Set["${monitorHeight}"]
mainWidth:Set["${monitorWidth}*${numInactiveRegions}/(${numInactiveRegions}+1)"]
smallWidth:Set["${monitorWidth}-${mainWidth}"]
smallHeight:Set["${monitorHeight}/${numInactiveRegions}"]
variable int useX=${monitorX}
if !${useRight}
useX:Set[${monitorX}+${smallWidth}]
; main region
joRegion:SetValue["$$>
{
"mainRegion":true,
"x":${useX},
"y":${monitorY},
"width":${mainWidth},
"height":${mainHeight},
"numRegion":1
}
<$$"]
ja:Add["${joRegion~}"]
variable int useY=${monitorY}
variable uint numSlot
useX:Set[${mainWidth}+${monitorX}]
if !${useRight}
{
useX:Set[${monitorX}]
}
joRegion:SetValue["$$>
{
"x":${useX},
"y":${useY},
"width":${smallWidth},
"height":${smallHeight}
}
<$$"]
for (numSlot:Set[1] ; ${numSlot}<=${numInactiveRegions} ; numSlot:Inc)
{
joRegion:SetInteger[y,${useY}]
joRegion:SetInteger[numRegion,${numSlot.Inc}]
ja:Add["${joRegion~}"]
useY:Inc["${smallHeight}"]
}
return ja
}
}
objectdef windowLayoutGenerator_Tile inherits windowLayoutGenerator_Common
{
method Initialize()
{
Name:Set[Tile]
Description:Set["Generates a layout where all windows are tiled"]
}
member:uint GetSquareSize(uint numRegions)
{
; find the best square
; size: max regions
; 2: 4
; 3: 9
; 4: 16
; 5: 25
; 6: 36
; 7: 49
; 8: 64
;echo GetSquareSize[${numRegions}]
variable uint squareSize=1
while ${squareSize}*${squareSize} < ${numRegions}
{
squareSize:Inc
}
return ${squareSize}
}
member:jsonvalueref GenerateRegions_Subclass(jsonvalueref joInput)
{
variable jsonvalue ja="[]"
variable jsonvalue joRegion
variable uint squareSize
squareSize:Set[${This.GetSquareSize[${numSlots}]}]
if !${squareSize}
return NULL
variable uint nX
variable uint nY
variable uint smallHeight
variable uint smallWidth
smallWidth:Set["${monitorWidth}/${squareSize}"]
smallHeight:Set["${monitorHeight}/${squareSize}"]
variable uint numSlot
joRegion:SetValue["$$>
{
"x":${monitorX},
"y":${monitorY},
"width":${smallWidth},
"height":${smallHeight}
}
<$$"]
for (nY:Set[0] ; ${nY} < ${squareSize} ; nY:Inc )
{
for (nX:Set[0] ; ${nX} < ${squareSize} ; nX:Inc )
{
numSlot:Inc
if ${numSlot} > ${numSlots}
break
joRegion:SetInteger[x,${monitorX.Inc[${nX} * ${smallWidth}]}]
joRegion:SetInteger[y,${monitorY.Inc[${nY} * ${smallHeight}]}]
joRegion:SetInteger[numRegion,${numSlot}]
ja:Add["${joRegion~}"]
}
if ${numSlot} > ${numSlots}
break
}
return ja
}
}
objectdef windowLayoutGenerator_Grid inherits windowLayoutGenerator_Common
{
method Initialize()
{
Name:Set[Grid]
Description:Set["Generates a layout where all windows are tiled within a specified grid"]
}
member:jsonvalueref GenerateRegions_Subclass(jsonvalueref joInput)
{
variable jsonvalue ja="[]"
variable jsonvalue joRegion
variable uint gridSizeX=${joInput.GetInteger[columns]}
variable uint gridSizeY=${joInput.GetInteger[rows]}
if ${gridSizeX}<1
gridSizeX:Set[1]
if ${gridSizeY}<1
gridSizeY:Set[1]
; echo Grid size ${gridSizeX}x${gridSizeY}
variable uint nX
variable uint nY
variable uint smallHeight
variable uint smallWidth
smallWidth:Set["${monitorWidth}/${gridSizeX}"]
smallHeight:Set["${monitorHeight}/${gridSizeY}"]
variable uint numSlot
joRegion:SetValue["$$>
{
"x":${monitorX},
"y":${monitorY},
"width":${smallWidth},
"height":${smallHeight}
}
<$$"]
while ${numSlot} <= ${numSlots}
{
for (nY:Set[0] ; ${nY} < ${gridSizeY} ; nY:Inc )
{
for (nX:Set[0] ; ${nX} < ${gridSizeX} ; nX:Inc )
{
numSlot:Inc
if ${numSlot} > ${numSlots}
break
joRegion:SetInteger[x,${monitorX.Inc[${nX} * ${smallWidth}]}]
joRegion:SetInteger[y,${monitorY.Inc[${nY} * ${smallHeight}]}]
joRegion:SetInteger[numRegion,${numSlot}]
ja:Add["${joRegion~}"]
}
if ${numSlot} > ${numSlots}
break
}
}
return ja
}
}