-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
xfce4-display-profile-chooser.sh
1257 lines (1127 loc) · 46 KB
/
xfce4-display-profile-chooser.sh
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
#!/bin/bash
# xfce4-display-profile-chooser
# Version: 0.4.2
# Author: KeyofBlueS
# Repository: https://github.com/KeyofBlueS/xfce4-display-profile-chooser
# License: GNU General Public License v3.0, https://opensource.org/licenses/GPL-3.0
function check_connected_edid() {
## TODO: check if configured displays in profile are connected. Help is needed, please see https://github.com/KeyofBlueS/xfce4-display-profile-chooser/issues/1
profile_id_check="${1}"
missing_edid='0'
profile_edids="$(echo "${profiles_ids_prop}" | grep "${profile_id_check}" | grep '/EDID ' | awk '{print $2}')"
for profile_edid in ${profile_edids}; do
for connected_edid in ${connected_edids}; do
if ! echo "${connected_edid}" | grep -xq "${profile_edid}"; then
missing_edid='1'
fi
done
done
}
function get_profile_name() {
get_name="${1}"
if [[ "${get_name}" = 'Default' || "${get_name}" = 'Fallback' ]]; then
profile_name="${get_name}"
else
#profile_name="$(echo "${profiles_ids_prop}" | grep "/${get_name}" | awk 'NR==1{for (i=1;i<=NF;i++) printf("%s ",$i)}' | grep -oP '(?<=\ ).*' | sed 's/ $//' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")"
profile_name="$(xfconf-query -c displays -p "/${get_name}")"
fi
}
function list_profiles() {
first_profile_item='0'
for profiles_id in ${profiles_ids}; do
#profile_name="$(get_profile_name "${profiles_id}")"
get_profile_name "${profiles_id}"
if [[ "${profiles_id}" = 'Default' ]] && [[ "${default_profile}" != 'true' ]]; then
continue
elif [[ "${profiles_id}" = 'Fallback' ]] && [[ "${fallback_profile}" != 'true' ]]; then
continue
fi
if [[ "${active_profile_id}" = "${profiles_id}" ]]; then
list_verbose_profiles "${profiles_id}" check_active
if [[ "${active_profile_state}" != '1' ]]; then
profile_state=', state: set; active'
profile_color='1;32'
else
profile_state=', state: set; not active'
profile_color='1;33'
fi
else
## TODO: check if configured displays in profile are connected. Help is needed, please see https://github.com/KeyofBlueS/xfce4-display-profile-chooser/issues/1
#check_connected_edid "${profiles_id}"
if [[ "${missing_edid}" = '1' ]]; then
if [[ "${unavailable_profile}" != 'true' ]]; then
continue
fi
profile_state=', state: not available'
profile_color='1;31'
else
#profile_state=', state: available'
profile_state=''
profile_color='2;32'
fi
fi
if [[ "${verbose}" = 'true' ]]; then
first_profile_item="$(("${first_profile_item}" + 1))"
list_verbose_profiles "${profiles_id}" show_verbose
else
echo -e "\e[${profile_color}mid: ${profiles_id}, name: ${profile_name}${profile_state}\e[0m"
fi
done
}
function list_verbose_profiles() {
get_verbose="${1}"
action_verbose="${2}"
if [[ "${action_verbose}" = 'show_verbose' ]]; then
if [[ "${first_profile_item}" -ge '2' ]]; then
echo
echo '-----------------------------------------------------------------'
echo
fi
echo -e "\e[${profile_color}mid: ${get_verbose}, name: ${profile_name}${profile_state}\e[0m"
elif [[ "${action_verbose}" = 'check_active' ]]; then
xrandr_prop="$(xrandr)"
active_profile_state='0'
elif [[ "${action_verbose}" = 'check_connected_supported' ]]; then
xrandr_prop="$(xrandr)"
not_connected_supported='0'
unset error_message
fi
profile_outputs="$(echo "${profiles_ids_prop}" | grep "${get_verbose}" | grep '/EDID ' | awk -F'/' '{print $3}')"
for profile_output in ${profile_outputs}; do
profile_output_prop="$(echo "${profiles_ids_prop}" | grep "/${get_verbose}/${profile_output}")"
unset position_x
unset position_y
unset primary
unset reflection
unset refreshrate
unset resolution
unset rotation
unset scale_x
unset scale_y
name="$(echo "${profile_output_prop}" | grep "${profile_output} " | awk 'NR==1{for (i=1;i<=NF;i++) printf("%s ",$i)}' | grep -oP '(?<=\ ).*' | sed 's/ $//')"
edid="$(echo "${profile_output_prop}" | grep '/EDID ' | awk '{print $2}')"
active="$(echo "${profile_output_prop}" | grep '/Active ' | awk '{print $2}')"
if [[ "${active}" = 'true' || "${get_verbose}" = 'Default' || "${get_verbose}" = 'Fallback' ]] && [[ "${action_verbose}" != 'remove_profile_output' ]]; then
position_x="$(echo "${profile_output_prop}" | grep '/Position/X ' | awk '{print $2}')"
position_y="$(echo "${profile_output_prop}" | grep '/Position/Y ' | awk '{print $2}')"
primary="$(echo "${profile_output_prop}" | grep '/Primary ' | awk '{print $2}')"
reflection="$(echo "${profile_output_prop}" | grep '/Reflection ' | awk '{print $2}')"
refreshrate="$(echo "${profile_output_prop}" | grep '/RefreshRate ' | awk '{print $2}')"
resolution="$(echo "${profile_output_prop}" | grep '/Resolution ' | awk '{print $2}')"
rotation="$(echo "${profile_output_prop}" | grep '/Rotation ' | awk '{print $2}')"
scale_x="$(echo "${profile_output_prop}" | grep '/Scale/X ' | awk '{print $2}')"
scale_y="$(echo "${profile_output_prop}" | grep '/Scale/Y ' | awk '{print $2}')"
if [[ -z "${scale_x}" ]] && [[ "${action_verbose}" != 'show_verbose' ]] && [[ "${action_verbose}" != 'set_default_fallback_profile' ]]; then
scale_x='1,000000'
fi
if [[ -z "${scale_y}" ]] && [[ "${action_verbose}" != 'show_verbose' ]] && [[ "${action_verbose}" != 'set_default_fallback_profile' ]]; then
scale_y='1,000000'
fi
fi
if [[ "${action_verbose}" = 'show_verbose' ]]; then
show_verbose_profiles
elif [[ "${action_verbose}" = 'check_active' ]]; then
check_active_profile
elif [[ "${action_verbose}" = 'check_connected_supported' ]]; then
check_connected_supported_display
elif [[ "${action_verbose}" = 'list_profile_output' ]] && [[ -n "${profile_output}" ]] && [[ -n "${name}" ]]; then
remove_profile_outputs+="${profile_output},${name}\n"
elif [[ "${action_verbose}" = 'set_default_fallback_profile' ]]; then
set_default_fallback_profile
fi
done
if [[ "${action_verbose}" = 'show_verbose' ]]; then
echo
echo 'xrandr command to set this profile:'
echo "xrandr${xrandr_command}"
unset xrandr_command
fi
unset action_verbose
}
function show_verbose_profiles() {
echo
echo "Output=${profile_output}"
echo "Name=${name}"
echo "EDID=${edid}"
echo "Active=${active}"
if [[ "${active}" = 'true' || "${get_verbose}" = 'Default' || "${get_verbose}" = 'Fallback' ]]; then
if [[ -n "${position_x}" ]]; then
echo "Position_X=${position_x}"
fi
if [[ -n "${position_y}" ]]; then
echo "Position_Y=${position_y}"
fi
if [[ -n "${primary}" ]]; then
echo "Primary=${primary}"
fi
if [[ -n "${reflection}" ]]; then
echo "Reflection=${reflection}"
fi
if [[ -n "${refreshrate}" ]]; then
echo "RefreshRate=${refreshrate}"
fi
if [[ -n "${resolution}" ]]; then
echo "Resolution=${resolution}"
fi
if [[ -n "${rotation}" ]]; then
echo "Rotation=${rotation}"
fi
if [[ -n "${scale_x}" ]]; then
echo "Scale_X=${scale_x}"
fi
if [[ -n "${scale_y}" ]]; then
echo "Scale_Y=${scale_y}"
fi
fi
while IFS= read -r xrandr_opt; do
xrandr_command="${xrandr_command} ${xrandr_opt}"
done <<< "$(xrandr_options)"
}
function xrandr_options() {
get_xrandr_variables
echo "--output ${xrandr_output}"
if [[ "${xrandr_active}" = 'false' ]]; then
echo "--off"
else
if [[ "${xrandr_primary}" = 'primary' ]]; then
echo "--primary"
fi
echo "--mode ${xrandr_resolution}"
echo "--rate ${xrandr_refreshrate}"
echo "--pos ${xrandr_position_x}x${xrandr_position_y}"
echo "--rotate ${xrandr_rotation}"
echo "--reflect ${xrandr_reflection}"
if [[ -n "${xrandr_scale_x}" ]] && [[ -n "${xrandr_scale_y}" ]]; then
echo "--scale ${xrandr_scale_x}x${xrandr_scale_y}"
fi
fi
}
function get_xrandr_variables() {
unset xrandr_output
unset xrandr_active
unset xrandr_primary
unset xrandr_resolution
unset xrandr_refreshrate
unset xrandr_position_x
unset xrandr_position_y
unset xrandr_rotation
unset xrandr_reflection
unset xrandr_scale_x
unset xrandr_scale_y
xrandr_output="${profile_output}"
xrandr_active="${active}"
if [[ -n "${position_x}" ]]; then
xrandr_position_x="${position_x}"
fi
if [[ -n "${position_y}" ]]; then
xrandr_position_y="${position_y}"
fi
if [[ -n "${primary}" ]] && [[ "${primary}" = 'true' ]]; then
xrandr_primary='primary'
fi
if [[ -n "${reflection}" ]]; then
if [[ "${reflection}" = '0' ]]; then
xrandr_reflection="normal"
else
xrandr_reflection="${reflection,,}"
fi
fi
if [[ -n "${refreshrate}" ]]; then
xrandr_refreshrate="${refreshrate}"
fi
if [[ -n "${resolution}" ]]; then
xrandr_resolution="${resolution}"
fi
if [[ -n "${rotation}" ]]; then
if [[ "${rotation}" = '0' ]]; then
xrandr_rotation="normal"
elif [[ "${rotation}" = '90' ]]; then
xrandr_rotation="left"
elif [[ "${rotation}" = '180' ]]; then
xrandr_rotation="inverted"
elif [[ "${rotation}" = '270' ]]; then
xrandr_rotation="right"
fi
fi
if [[ -n "${scale_x}" ]]; then
xrandr_scale_x="${scale_x//,/$'.'}"
fi
if [[ -n "${scale_y}" ]]; then
xrandr_scale_y="${scale_y//,/$'.'}"
fi
}
function check_active_profile() {
get_xrandr_variables
if echo "${xrandr_prop}" | grep -q "${xrandr_output} connected"; then
unset xrandr_primary_state
unset xrandr_resolution_state
unset xrandr_position_state
unset xrandr_rotation_state
unset xrandr_reflection_state
unset xrandr_refreshrate_state
if [[ "${xrandr_active}" = 'true' ]]; then
if [[ "${xrandr_primary}" = 'primary' ]]; then
xrandr_primary_state="${xrandr_primary}"
fi
if [[ "${xrandr_rotation}" = 'left' || "${xrandr_rotation}" = 'right' ]]; then
xrandr_resolution_state="$(echo "${xrandr_resolution}" | awk -F'x' '{print $2}')x$(echo "${xrandr_resolution}" | awk -F'x' '{print $1}')"
else
xrandr_resolution_state="${xrandr_resolution}"
fi
if [[ "${xrandr_scale_x}" != '1.000000' || "${xrandr_scale_y}" != '1.000000' ]]; then
xrandr_resolution_state="$(echo - | awk "{print "$(echo "${xrandr_resolution_state}" | awk -F'x' '{print $1}')" * "${xrandr_scale_x}"}")x$(echo - | awk "{print "$(echo "${xrandr_resolution_state}" | awk -F'x' '{print $2}')" * "${xrandr_scale_y}"}")"
fi
xrandr_position_state="+${xrandr_position_x}+${xrandr_position_y}"
if [[ "${xrandr_rotation}" != 'normal' ]]; then
xrandr_rotation_state="${xrandr_rotation}"
fi
if [[ "${xrandr_reflection}" != 'normal' ]]; then
if [[ "${xrandr_reflection}" = 'x' || "${xrandr_reflection}" = 'y' ]]; then
xrandr_reflection_state="${xrandr_reflection^^} axis"
elif [[ "${xrandr_reflection}" = 'xy' ]]; then
xrandr_reflection_state="X and Y axis"
fi
fi
xrandr_refreshrate_state="${xrandr_refreshrate//,/$'.'}"
xrandr_refreshrate_state="$(echo "${xrandr_refreshrate_state}" | awk -F'.' '{print $1}')"
xrandr_refreshrate_state_plus="$((${xrandr_refreshrate_state}+1))"
xrandr_refreshrate_state_minus="$((${xrandr_refreshrate_state}-1))"
unset xrandr_grep
for xrandr_state in ${xrandr_output} connected ${xrandr_primary_state} ${xrandr_resolution_state}${xrandr_position_state} ${xrandr_rotation_state} ${xrandr_reflection_state}; do
if [[ -z "${xrandr_grep}" ]]; then
xrandr_grep="${xrandr_state}"
else
xrandr_grep+=" ${xrandr_state}"
fi
done
xrandr_output_prop="$(echo "${xrandr_prop}" | awk -v output="^${xrandr_output} connected" '/connected/ {p = 0} $0 ~ output {p = 1} p')"
if ! echo "${xrandr_output_prop}" | grep -q "${xrandr_grep} ("; then
active_profile_state='1'
else
if ! echo "${xrandr_output_prop}" | grep -Eq " +(${xrandr_refreshrate_state}|${xrandr_refreshrate_state_plus}|${xrandr_refreshrate_state_minus})\.[[:digit:]]+\*"; then
active_profile_state='1'
fi
fi
else
if ! echo "${xrandr_prop}" | grep -q "${xrandr_output} connected ("; then
active_profile_state='1'
fi
fi
else
if [[ "${skip_inactive}" != 'true' ]]; then
active_profile_state='1'
fi
fi
}
function check_connected_supported_display() {
get_xrandr_variables
if echo "${xrandr_prop}" | grep -q "${xrandr_output} connected"; then
if [[ "${xrandr_active}" = 'true' ]]; then
xrandr_output_prop="$(echo "${xrandr_prop}" | awk -v output="^${xrandr_output} connected" '/connected/ {p = 0} $0 ~ output {p = 1} p')"
xrandr_refreshrate_connected="${xrandr_refreshrate//,/$'.'}"
xrandr_refreshrate_connected="$(echo "${xrandr_refreshrate_connected}" | awk -F'.' '{print $1}')"
xrandr_refreshrate_connected_plus="$((${xrandr_refreshrate_connected}+1))"
xrandr_refreshrate_connected_minus="$((${xrandr_refreshrate_connected}-1))"
if ! echo "${xrandr_output_prop}" | grep -E "^ +${xrandr_resolution}" | grep -Eq " +(${xrandr_refreshrate_connected}|${xrandr_refreshrate_connected_plus}|${xrandr_refreshrate_connected_minus})\.[[:digit:]]+"; then
not_connected_supported='1'
if [[ -z "${error_message}" ]]; then
error_message="$(echo -e "\e[1;31mDisplay connected to ${xrandr_output} do not support this profile (${xrandr_resolution} ${xrandr_refreshrate_connected}Hz).\e[0m")"
else
error_message+="\n$(echo -e "\e[1;31mDisplay connected to ${xrandr_output} do not support this profile (${xrandr_resolution} ${xrandr_refreshrate_connected}Hz).\e[0m")"
fi
fi
fi
else
if [[ "${skip_inactive}" = 'true' ]]; then
if [[ "${xrandr_active}" = 'false' ]]; then
echo -e "\e[1;33mSkipping display connected to ${xrandr_output} as it is inactive in this profile\e[0m"
else
not_connected_supported='1'
if [[ -z "${error_message}" ]]; then
error_message="$(echo -e "\e[1;31mNo Display connected to ${xrandr_output}.\e[0m")"
else
error_message+="\n$(echo -e "\e[1;31mNo Display connected to ${xrandr_output}.\e[0m")"
fi
fi
else
not_connected_supported='1'
if [[ -z "${error_message}" ]]; then
error_message="$(echo -e "\e[1;31mNo Display connected to ${xrandr_output}.\e[0m")"
else
error_message+="\n$(echo -e "\e[1;31mNo Display connected to ${xrandr_output}.\e[0m")"
fi
fi
fi
}
function set_rem_profile_menu() {
print_separator
while true; do
if [[ "${current_action}" = 'set_profile' ]]; then
echo -e "\e[1;32mSelect the profile you want to set:\e[0m"
elif [[ "${current_action}" = 'remove_profile' ]]; then
echo -e "\e[1;31mSelect the profile you want to remove:\e[0m"
fi
echo -e "\e[1;32m0) Exit\e[0m"
unset verbose
unset set_rem_profile_list
local i=0
while IFS= read -r exp_profile; do
i=$((i + 1))
if [[ -z "${set_rem_profile_list}" ]]; then
set_rem_profile_list+="${i}) ${exp_profile}"
else
set_rem_profile_list+="\n${i}) ${exp_profile}"
fi
done <<< "$(list_profiles)"
echo -e "${set_rem_profile_list}"
read -p "make your choice: " selected_profile
if [[ ! "${selected_profile}" =~ ^[[:digit:]]+$ ]] || [[ "${selected_profile}" -gt "${i}" ]]; then
echo
echo -e "\e[1;31m## WRONG INPUT.......please be more careful\e[0m"
echo
else
if [[ "${selected_profile}" = '0' ]]; then
break
else
selected_profile_id="$(echo -e "${set_rem_profile_list}" | sed -n "${selected_profile}"p | awk -F'id: ' '{print $2}' | awk -F',' '{print $1}')"
if [[ "${current_action}" = 'set_profile' ]]; then
profile_id_set="${selected_profile_id}"
set_profile
set_default_fallback_profile_inizialize
elif [[ "${current_action}" = 'remove_profile' ]]; then
profile_id_rem="${selected_profile_id}"
remove_profile
fi
fi
fi
inizialize
unset yad
done
}
function set_profile() {
set_rem_profile_inizialize "${profile_id_set}"
if [[ "${error}" != '1' ]]; then
if [[ "${active_profile_id}" = "${profile_id_set}" ]]; then
list_verbose_profiles "${profile_id_set}" check_active
if [[ "${active_profile_state}" != '1' ]]; then
echo -e "\e[1;33mProfile ${profile_id_set} - ${profile_name} is already active\e[0m"
error='1'
fi
fi
## TODO: check if configured displays in profile are connected. Help is needed, please see https://github.com/KeyofBlueS/xfce4-display-profile-chooser/issues/1
#check_connected_edid "${profile_id_set}"
if [[ "${missing_edid}" = '1' ]]; then
error='1'
set_profile_error
fi
if [[ "${error}" != '1' ]]; then
list_verbose_profiles "${profile_id_set}" check_connected_supported
if [[ "${not_connected_supported}" = '1' ]]; then
error='1'
error_message="${error_message}\n$(echo -e "\e[1;31mCannot set profile ${profile_id_set} - ${profile_name}.\e[0m")"
echo -e "${error_message}"
else
xfconf-query --create -c displays -p "/Schemes/Apply" -t string -s "${profile_id_set}"
echo -e "\e[2;32mProfile ${profile_id_set} - ${profile_name} is set\e[0m"
if [[ "${ask_keep_config}" = 'true' ]] && [[ "${keep_config_ask_count}" != '1' ]] && [[ "${yad}" != '1' ]]; then
keep_config_ask
fi
unset keep_config_ask_count
fi
fi
fi
}
function set_default_fallback_profile_inizialize() {
if [[ "${profile_id_set}" != 'Default' ]] && [[ "${profile_id_set}" != 'Fallback' ]] && [[ "${error}" != '1' ]]; then
echo "Setting Default and Fallback profiles..."
for default_fallback in Default ${profile_id_set}; do
if [[ "${default_fallback}" = 'Default' ]]; then
xfconf-query --reset -c displays --property "/Fallback" --recursive
else
xfconf-query --reset -c displays --property "/Default" --recursive
fi
list_verbose_profiles "${default_fallback}" 'set_default_fallback_profile'
done
fi
}
function set_default_fallback_profile() {
if [[ "${get_verbose}" = 'Default' ]]; then
set_default_fallback='Fallback'
else
set_default_fallback='Default'
fi
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}" --type string -s "${name}"
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Active" --type bool -s "${active}"
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/EDID" --type string -s "${edid}"
if [[ -n "${position_x}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Position/X" --type int -s "${position_x}"
fi
if [[ -n "${position_y}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Position/Y" --type int -s "${position_y}"
fi
if [[ -n "${primary}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Primary" --type bool -s "${primary}"
fi
if [[ -n "${reflection}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Reflection" --type string -s "${reflection}"
fi
if [[ -n "${refreshrate}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/RefreshRate" --type double -s "${refreshrate//,/$'.'}"
fi
if [[ -n "${resolution}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Resolution" --type string -s "${resolution}"
fi
if [[ -n "${rotation}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Rotation" --type int -s "${rotation}"
fi
if [[ -n "${scale_x}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Scale/X" --type double -s "${scale_x//,/$'.'}"
fi
if [[ -n "${scale_y}" ]]; then
xfconf-query -c displays --create -p "/${set_default_fallback}/${profile_output}/Scale/Y" --type double -s "${scale_y//,/$'.'}"
fi
}
function keep_config_ask() {
keep_config_ask_count='1'
restore_count="${restore_countdown}"
echo -e "\e[1;33mWould you like to keep this configuration?\e[0m"
echo -e "\e[1;33mThe previous configuration will be restored in ${restore_countdown} seconds if you not reply to this question. \e[0m"
echo -e "\e[1;35m (K)eep this configuration\e[0m"
echo -e "\e[1;35m (R)estore the previous configuration\e[0m"
until [[ "${restore_count}" -eq '0' ]]; do
unset keep_config_answer
echo -en "\r\e[1;33mRestoring the previous configuration in \e[1;31m${restore_count}\e[1;33m \e[0m\c"
read -s -t 1 -N 1 keep_config_answer
keep_config_answer="${keep_config_answer,,}"
if [[ -n "${keep_config_answer}" ]]; then
if [[ "${keep_config_answer}" = 'k' || "${keep_config_answer}" = 'r' ]]; then
break
else
echo -en "\e[1;31m\rInvalid choice!\e[0m\c"
sleep 1
fi
fi
((restore_count-=1))
done
if [[ "${restore_count}" -eq '0' ]]; then
echo -en "\r\e[1;33mRestoring the previous configuration in \e[1;31m${restore_count}\e[1;33m \e[0m\c"
fi
echo
if [[ "${keep_config_answer}" = 'k' ]]; then
true
else
echo -e "\e[1;33mRestoring the previous configuration...\e[0m"
profile_id_set="${active_profile_id}"
inizialize
set_profile
fi
}
function remove_profile() {
set_rem_profile_inizialize "${profile_id_rem}"
if [[ "${error}" != '1' ]]; then
while true; do
unset remove_profile_outputs
list_verbose_profiles "${profile_id_rem}" list_profile_output
if [[ -z "${remove_profile_outputs}" ]] && [[ -n "${profile_id_rem}" ]]; then
echo -e "\e[1;31m${profile_id_rem} - ${profile_name} doesn't contain any output. Removing it...\e[0m"
xfconf-query --reset -c displays --property "/${profile_id_rem}" --recursive
echo -e "\e[1;33mProfile ${profile_id_rem} - ${profile_name} removed\e[0m"
break
fi
echo
echo -e "\e[1;31mAre you sure you want to remove profile ${profile_id_rem} - ${profile_name}?\e[0m"
if [[ "${profile_id_rem}" = 'Default' || "${profile_id_rem}" = 'Fallback' ]]; then
echo -e "\e[1;31mWARNING: It is not recommended to remove ${profile_id_rem} profile!\e[0m"
fi
echo -e "\e[1;31mWARNING: This action can't be undone!\e[0m"
echo -e "\e[1;32m0) No\e[0m"
echo -e "\e[1;31m1) Yes\e[0m"
echo -e "\e[1;31m2) Remove single outputs from this profile...\e[0m"
read -p "make your choice: " rem_input
case "${rem_input}" in
0) {
echo
echo -e "\e[1;32mProfile ${profile_id_rem} - ${profile_name} not removed\e[0m"
break
};;
1) {
if [[ -n "${profile_id_rem}" ]]; then
xfconf-query --reset -c displays --property "/${profile_id_rem}" --recursive
echo
echo -e "\e[1;33mProfile ${profile_id_rem} - ${profile_name} removed\e[0m"
break
fi
};;
2) {
remove_profile_output
};;
*) {
echo
echo -e "\e[1;31m## WRONG INPUT.......please be more careful\e[0m"
echo
};;
esac
done
fi
}
function remove_profile_output() {
while true; do
unset remove_profile_outputs
inizialize
list_verbose_profiles "${profile_id_rem}" list_profile_output
if [[ -z "${remove_profile_outputs}" ]]; then
break
fi
echo
echo -e "\e[1;31mSelect the output you want to remove from profile ${profile_id_rem} - ${profile_name}\e[0m"
echo -e "\e[1;32m0) Go back\e[0m"
unset remove_profile_outputs_list
local i=0
while IFS=, read -r exp_output exp_name; do
i=$((i + 1))
if [[ -z "${remove_profile_outputs_list}" ]]; then
remove_profile_outputs_list+="${i}) ${exp_name} on ${exp_output}"
else
remove_profile_outputs_list+="\n${i}) ${exp_name} on ${exp_output}"
fi
done <<< "$(echo -e "${remove_profile_outputs}")"
echo -e "\e[1;31m${remove_profile_outputs_list}\e[0m"
read -p "make your choice: " selected_output
if [[ ! "${selected_output}" =~ ^[[:digit:]]+$ ]] || [[ "${selected_output}" -gt "${i}" ]]; then
echo
echo -e "\e[1;31m## WRONG INPUT.......please be more careful\e[0m"
echo
else
if [[ "${selected_output}" = '0' ]]; then
break
else
remove_profile_output_name="$(echo -e "${remove_profile_outputs_list}" | sed -n "${selected_output}"p | awk -F') ' '{print $2}')"
remove_profile_output="$(echo "${remove_profile_output_name}" | rev | awk '{print $1}' | rev)"
while true; do
echo
echo -e "\e[1;31mAre you sure you want to remove ${remove_profile_output_name} from profile ${profile_id_rem} - ${profile_name}?\e[0m"
echo -e "\e[1;31mWARNING: This action can't be undone!\e[0m"
echo -e "\e[1;31mWARNING: If you remove all outputs, the whole profile will be deleted!\e[0m"
echo -e "\e[1;32m0) No\e[0m"
echo -e "\e[1;31m1) Yes\e[0m"
read -p "make your choice: " rem_output_input
case "${rem_output_input}" in
0) {
echo
echo -e "\e[1;32m${remove_profile_output_name} from profile ${profile_id_rem} - ${profile_name} not removed\e[0m"
break
};;
1) {
if [[ -n "${profile_id_rem}" ]]; then
xfconf-query --reset -c displays --property "/${profile_id_rem}/${remove_profile_output}" --recursive
echo
echo -e "\e[1;33m${remove_profile_output_name} from profile ${profile_id_rem} - ${profile_name} removed\e[0m"
break
fi
};;
*) {
echo
echo -e "\e[1;31m## WRONG INPUT.......please be more careful\e[0m"
echo
};;
esac
done
fi
fi
done
}
function set_rem_profile_inizialize() {
profile_id_set_rem="${1}"
print_separator
unset error
#profile_name="$(get_profile_name "${profile_id_set_rem}")"
get_profile_name "${profile_id_set_rem}"
exist='0'
for profiles_id in ${profiles_ids}; do
if echo "${profiles_id}" | grep -xq "${profile_id_set_rem}"; then
exist='1'
fi
done
if [[ "${exist}" = '0' ]]; then
echo -e "\e[1;31mProfile id ${profile_id_set_rem} does not exist\e[0m"
error='1'
fi
}
function print_separator() {
if echo "${actions}" | grep -q 'list_profiles'; then
echo
if [[ "${verbose}" = 'true' ]]; then
echo '-----------------------------------------------------------------'
echo
fi
fi
}
function set_profile_error() {
echo -e "\e[1;31mOne or more display in this profile are not connected.\e[0m"
echo -e "\e[1;31mCannot set profile ${profile_id_set} - ${profile_name}\e[0m"
}
function yad_chooser() {
ycommopt='--always-print-result --title=xfce4-display-profile-chooser --center --image-on-top --wrap --buttons-layout=spread'
yad_check_error
while true; do
if pgrep -a yad | grep -q "title=xfce4-display-profile-chooser"; then
wmctrl -FR "xfce4-display-profile-chooser"
echo -e "\e[1;33mWARNING: Another instance of xfce4-display-profile-chooser is running."
exit 0
fi
inizialize
unset verbose
profiles="$(list_profiles | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")"
profiles_names="$(echo "${profiles}" | awk -F'name: ' '{print $2}' | sort)"
while IFS= read -r profiles_name; do
if [[ -z "${profiles_list}" ]]; then
profiles_list="${profiles_name}"
else
profiles_list+="!${profiles_name}"
fi
done <<< "${profiles_names}"
active_profile_name="$(echo "${profiles_names}" | grep 'state: set')"
active_profile_state='0'
not_connected_supported='0'
#profile_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --image "avatar-default" --text="Current profile: ${active_profile_name}" --form --field="Profile:CB" "${profiles_list}" --field="Show Default profile":chk "${default_profile}" --field="Show Fallback profile":chk "${fallback_profile}" --field="Show unavailable profiles":chk "${unavailable_profile}" --field="Skip checks on inactive outputs":chk "${skip_inactive}" --field="Ask if keep or restore profile":chk "${ask_keep_config}" --button="Exit"!exit!Exit:99
profile_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --image "avatar-default" --text="Current profile: ${active_profile_name}" --form --field="Profile:CB" "${profiles_list}" --field="Show Default profile":chk "${default_profile}" --field="Show Fallback profile":chk "${fallback_profile}" --field="Skip checks on inactive outputs":chk "${skip_inactive}" --field="Ask if keep or restore profile":chk "${ask_keep_config}" --button="Exit"!exit!Exit:99 \
--button="Help"!help-about!"Show help":98 \
--button="Info"!user-info!"Show profiles info":97 \
--button="Display"!org.xfce.settings.display!"Open xfce4-display-settings":96 \
--button="Remove profile"!user-trash-full!"Remove selected profile":95 \
--button="Refresh"!view-refresh!"Refresh profiles list":94 \
--button="Set profile"!dialog-apply!"Set selected profile":93)"
profile_choice="${?}"
default_profile="$(echo "${profile_yad}" | awk -F'|' '{print $2}' | tr '[:upper:]' '[:lower:]')"
fallback_profile="$(echo "${profile_yad}" | awk -F'|' '{print $3}' | tr '[:upper:]' '[:lower:]')"
skip_inactive="$(echo "${profile_yad}" | awk -F'|' '{print $4}' | tr '[:upper:]' '[:lower:]')"
ask_keep_config="$(echo "${profile_yad}" | awk -F'|' '{print $5}' | tr '[:upper:]' '[:lower:]')"
#unavailable_profile="$(echo "${profile_yad}" | awk -F'|' '{print $5}' | tr '[:upper:]' '[:lower:]')"
if [[ "${profile_choice}" -eq '99' ]]; then
exit 0
elif [[ "${profile_choice}" -eq '98' ]]; then
yad_help
elif [[ "${profile_choice}" -eq '97' ]]; then
yad_verbose
elif [[ "${profile_choice}" -eq '96' ]]; then
xfce4-display-settings
elif [[ "${profile_choice}" -eq '95' ]]; then
yad_profile_name="$(echo "${profile_yad}" | awk -F'|' '{print $1}' | awk -F',' '{print $1}')"
profile_id_rem="$(echo "${profiles}" | awk -F', state: ' '{print $1}' | grep ", name: ${yad_profile_name}$" | awk -F'id: ' '{print $2}' | awk -F',' '{print $1}')"
yad_remove_profile
elif [[ "${profile_choice}" -eq '94' ]]; then
true
elif [[ "${profile_choice}" -eq '93' ]]; then
yad_profile_name="$(echo "${profile_yad}" | awk -F'|' '{print $1}' | awk -F',' '{print $1}')"
profile_id_set="$(echo "${profiles}" | awk -F', state: ' '{print $1}' | grep ", name: ${yad_profile_name}$" | awk -F'id: ' '{print $2}' | awk -F',' '{print $1}')"
yad='1'
set_profile
if [[ "${missing_edid}" = '1' ]]; then
error_text="$(set_profile_error | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")"
yad_show_error
fi
if [[ "${not_connected_supported}" = '1' ]]; then
error_text="$(echo -e ${error_message} | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")"
yad_show_error
fi
if [[ "${ask_keep_config}" = 'true' ]] && [[ "${missing_edid}" != '1' ]] && [[ "${not_connected_supported}" != '1' ]] && [[ "${yad_profile_name}" != "${active_profile_name}" ]]; then
yad_keep_config
fi
set_default_fallback_profile_inizialize
else
exit 0
fi
unset profiles_list
done
}
function yad_keep_config() {
restore_count="${restore_countdown}"
start_count="${restore_count}"
until [[ "${restore_count}" -eq '0' ]]; do
percent_count=$((100-100*restore_count/start_count))
echo "#The previous configuration will be restored in ${restore_count} seconds if you not reply to this question."
echo "${percent_count}"
if [[ "${restore_count}" != '0' ]]; then
sleep 1
fi
((restore_count-=1))
done | yad ${ycommopt} --progress --percentage=0 --text="Would you like to keep this configuration?"\
--window-icon "xfce-display-external" --auto-close --button="Keep this configuration":99 \
--button="Restore the previous configuration":98
keep_config_answer="${?}"
if [[ "${keep_config_answer}" = '99' ]]; then
true
else
echo -e "\e[1;33mRestoring the previous configuration...\e[0m"
profile_id_set="$(echo "${profiles}" | grep ", name: ${active_profile_name}" | awk '{print $2}' | awk -F',' '{print $1}')"
inizialize
yad='1'
set_profile
unset yad
fi
}
function yad_help() {
info_help="$(givemehelp)"
help_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --image "help-about" --text="Help" --width=1100 --height=500 --text-info <<<"${info_help}" --button="Exit"!exit!Exit:99 \
--button="Go back"!back!"Go back to profile selection menu":98)"
help_choice="${?}"
if [[ "${help_choice}" -eq '99' ]]; then
exit 0
elif [[ "${help_choice}" -eq '98' ]]; then
true
else
exit 0
fi
}
function yad_verbose() {
while true; do
verbose='true'
inizialize
info_verbose="$(list_profiles | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")"
#verbose_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --width=900 --height=800 --form --field="Profiles info:":txt "${info_verbose}" --field="Show Default profile":chk "${default_profile}" --field="Show Fallback profile":chk "${fallback_profile}" --field="Show unavailable profiles":chk "${unavailable_profile}" --field="Skip checks on inactive outputs":chk "${skip_inactive}" --button="Exit"!exit!Exit:99
verbose_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --width=900 --height=800 --form --field="Profiles info:":txt "${info_verbose}" --field="Show Default profile":chk "${default_profile}" --field="Show Fallback profile":chk "${fallback_profile}" --field="Skip checks on inactive outputs":chk "${skip_inactive}" --button="Exit"!exit!Exit:99 \
--button="Refresh"!view-refresh!"Refresh profiles info":98 \
--button="Go back"!back!"Go back to profile selection menu":97)"
verbose_choice="${?}"
default_profile="$(echo "${verbose_yad}" | awk -F'|' '{print $2}' | tr '[:upper:]' '[:lower:]')"
fallback_profile="$(echo "${verbose_yad}" | awk -F'|' '{print $3}' | tr '[:upper:]' '[:lower:]')"
skip_inactive="$(echo "${verbose_yad}" | awk -F'|' '{print $4}' | tr '[:upper:]' '[:lower:]')"
#unavailable_profile="$(echo "${profile_yad}" | awk -F'|' '{print $5}' | tr '[:upper:]' '[:lower:]')"
if [[ "${verbose_choice}" -eq '99' ]]; then
exit 0
elif [[ "${verbose_choice}" -eq '98' ]]; then
true
elif [[ "${verbose_choice}" -eq '97' ]]; then
break
else
exit 0
fi
done
}
function yad_remove_profile() {
while true; do
list_verbose_profiles "${profile_id_rem}" list_profile_output
if [[ -z "${remove_profile_outputs}" ]] && [[ -n "${profile_id_rem}" ]]; then
echo "${yad_profile_name} doesn't contain any output. Removing it..."
xfconf-query --reset -c displays --property "/${profile_id_rem}" --recursive
echo -e "\e[1;33mProfile ${profile_id_rem} - ${yad_profile_name} removed\e[0m"
break
fi
unset default_fallback_rem_message
if [[ "${profile_id_rem}" = 'Default' || "${profile_id_rem}" = 'Fallback' ]]; then
default_fallback_rem_message="\nWARNING: It is not recommended to remove ${profile_id_rem} profile!"
fi
remove_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --image "dialog-warning" --text="Are you sure you want to remove profile ${yad_profile_name}?${default_fallback_rem_message}\nWARNING: This action can't be undone!" --button="Exit"!exit!Exit:99 \
--button="Confirm"!user-trash-full!"Remove selected profile":98 \
--button="Remove Outputs..."!video-display!"Remove single outputs from this profile...":97 \
--button="Go back"!back!"Go back to profile selection menu":96)"
rem_choice="${?}"
if [[ "${rem_choice}" -eq '99' ]]; then
exit 0
elif [[ "${rem_choice}" -eq '98' ]]; then
if [[ -n "${profile_id_rem}" ]]; then
xfconf-query --reset -c displays --property "/${profile_id_rem}" --recursive
echo -e "\e[1;33mProfile ${profile_id_rem} - ${yad_profile_name} removed\e[0m"
break
fi
elif [[ "${rem_choice}" -eq '97' ]]; then
yad_remove_profile_outputs
elif [[ "${rem_choice}" -eq '96' ]]; then
echo -e "\e[1;32mProfile ${profile_id_rem} - ${yad_profile_name} not removed\e[0m"
break
else
exit 0
fi
done
}
function yad_remove_profile_outputs() {
while true; do
unset profile_outputs_list
unset remove_profile_outputs
inizialize
list_verbose_profiles "${profile_id_rem}" list_profile_output
if [[ -z "${remove_profile_outputs}" ]]; then
break
fi
while IFS=, read -r exp_output exp_name; do
if [[ -z "${profile_outputs_list}" ]]; then
profile_outputs_list="${exp_name} on ${exp_output}"
else
profile_outputs_list+="!${exp_name} on ${exp_output}"
fi
done <<< "$(echo -e "${remove_profile_outputs}")"
profile_outputs_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --image "video-display" --text="Select the output you want to remove from profile ${yad_profile_name}" --form --field="Output:CB" "${profile_outputs_list}" --button="Exit"!exit!Exit:99 \
--button="Confirm"!user-trash-full!"Remove selected output":98 \
--button="Go back"!back!"Go back to profile removal menu":97)"
rem_choice="${?}"
if [[ "${rem_choice}" -eq '99' ]]; then
exit 0
elif [[ "${rem_choice}" -eq '98' ]]; then
profile_output_name="$(echo "${profile_outputs_yad}" | awk -F'|' '{print $1}')"
profile_output_rem="$(echo "${profile_output_name}" | rev | awk '{print $1}' | rev)"
yad_remove_profile_output
elif [[ "${rem_choice}" -eq '97' ]]; then
break
else
exit 0
fi
done
}
function yad_remove_profile_output() {
profile_output_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --image "dialog-warning" --text="Are you sure you want to remove ${profile_output_name} from profile ${yad_profile_name}?\nWARNING: This action can't be undone!\nWARNING: If you remove all outputs, the whole profile will be deleted!" --button="Exit"!exit!Exit:99 \
--button="Confirm"!user-trash-full!"Remove selected output":98 \
--button="Go back"!back!"Go back to profile output removal menu":97)"
rem_choice="${?}"
if [[ "${rem_choice}" -eq '99' ]]; then
exit 0
elif [[ "${rem_choice}" -eq '98' ]]; then
echo "${profile_id_rem} ${profile_output_rem}"
if [[ -n "${profile_id_rem}" ]]; then
xfconf-query --reset -c displays --property "/${profile_id_rem}/${profile_output_rem}" --recursive
echo -e "\e[1;33m${profile_output_name} from profile ${profile_id_rem} - ${yad_profile_name} removed\e[0m"
fi
elif [[ "${rem_choice}" -eq '97' ]]; then
echo -e "\e[1;32m${profile_output_name} from profile ${profile_id_rem} - ${yad_profile_name} not removed\e[0m"
else
exit 0
fi
}
function yad_check_error() {
check_dependencies
if [[ "${gui_error}" = '1' ]]; then
dependencies_error
exit 1
elif [[ "${commline_error}" = '1' ]]; then
error_text="$(dependencies_error | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")"
yad_show_error
exit 1
fi
check_xfce
if [[ "${not_xfce}" = '1' ]]; then
error_text="$(xfce_error | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")"
yad_show_error
exit 1
fi
}
function yad_show_error() {
error_yad="$(yad ${ycommopt} --window-icon "xfce-display-external" --image "dialog-error" --text="Error:" --width=1000 --height=200 --text-info <<<"${error_text}" --button="Exit"!exit!Exit:99)"
}