-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathaltyo_window.vala
More file actions
3563 lines (3103 loc) · 136 KB
/
altyo_window.vala
File metadata and controls
3563 lines (3103 loc) · 136 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
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
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
using Gtk;
using Cairo;
public class point_a {
public unowned Gtk.ActionGroup ag;
public StringBuilder sb;
public point_a(Gtk.ActionGroup ag) {
this.ag=ag;
this.sb=new StringBuilder();
}
}
public enum WStates{
VISIBLE,
HIDDEN
}
public enum TASKS{
TERMINALS,
QLIST
}
public enum TAB_SORT_ORDER{
NONE,
HOSTNAME
}
public enum SEARCH_MODE{
SEARCH_IN_TEXT,
SEARCH_IN_NAME
}
public enum NEW_TAB_MODE{
RIGHT_NEXT,
FAR_RIGHT
}
public enum OPTIONS_TAB{
SEARCH,
ENCODINGS
}
public enum MYWINStates{
NULL,
MAXIMIZED,
FULLSCREEN
}
public enum HVBOXDISPLAY{
VISIBLE,
HIDDEN,
HIDEIFONETAB
}
public delegate void MyCallBack(Gtk.Action a);
public class VTMainWindow : Window{
public OffscreenWindow pixwin;
public AYObject ayobject;
private int my_window_state;
private bool wait_window_manager=false;
private bool not_configured=true;//prevent some errors while starting
private uint wait_for_window_position_update=0;
private uint on_monitor_changed_force_new_position_glib_timer_id=0;
private uint update_position_size_for_glib_timer_id=0;
private bool _maximized=false;//cached value
public bool maximized {
get {
var win = this.get_window();
if( win!=null ){
if( (win.get_state() & Gdk.WindowState.MAXIMIZED) == Gdk.WindowState.MAXIMIZED){
_maximized=true;
this.get_style_context().add_class("window_maximized");
return true;
}else{
_maximized=false;
this.get_style_context().remove_class("window_maximized");
return false;
}
}else
return _maximized;
}//get
set {
if(value == true){
debug("mainvt_maximize");
this.my_window_state |= MYWINStates.MAXIMIZED;
if(!this.maximized){
this.wait_window_manager=true;
this.maximize();
if(this.fullscreen_on_maximize)
this.fullscreened=true;
}
}else{
debug("mainvt_unmaximize");
this.my_window_state &= ~(MYWINStates.MAXIMIZED);
this.fullscreened=false;
if(this.maximized){
this.wait_window_manager=true;
this.wait_for_window_position_update=5;
this.width_request=-1;//allow main window resize
this.height_request=-1;//allow main window resize
this.unmaximize();
}
}
}//set
}//public bool maximized
private bool _fullscreened=false;
public bool fullscreened {
get{
var win = this.get_window();
if( win!=null ){
if( (win.get_state() & Gdk.WindowState.FULLSCREEN) == Gdk.WindowState.FULLSCREEN ){
_fullscreened=true;
return true;
}else{
_fullscreened=false;
return false;
}
}else
return _fullscreened;
}
set{
if(value == true){
this.my_window_state |= MYWINStates.FULLSCREEN;
this.fullscreen();
}else{
this.my_window_state &= ~MYWINStates.FULLSCREEN;
if(this.fullscreened){
this.unfullscreen();
}
}
}
}//public bool fullscreen
public bool allow_update_size {
get{
//~ debug("maximized=%d fullscreened=%d update_maximized_size=%d update_minimized_size=%d pull_animation_active=%d pull_active=%d standalone_mode=%d wait_window_manager=%d" ,
//~ (int)this.maximized,
//~ (int)this.fullscreened,
//~ (int)this.update_maximized_size,
//~ (int)this.update_minimized_size,
//~ (int)this.pull_animation_active,
//~ (int)this.pull_active,
//~ (int)this.conf.standalone_mode,
//~ (int)this.wait_window_manager);
if(!this.conf.standalone_mode &&
!this.maximized &&
!this.fullscreened &&
!this.pull_animation_active &&
!this.pull_active &&
!this.not_configured &&
!this.wait_window_manager)
return true;
else
return false;
}
}
public bool fullscreen_on_maximize=false;
public bool animation_enabled = true;
public int animation_speed=20;//50hz
public int pull_steps=20;
public bool pull_animation_active = false;
public bool pull_active = false;
public bool pull_update_maximize_size = false; /*used to update size on pull down*/
public WStates current_state {get;set; default = WStates.VISIBLE;}
public unowned MySettings conf {get;set; default = null;}
public bool keep_above=true;
public bool orig_stick=true;
public PanelHotkey hotkey;
public bool mouse_follow=false;
public unowned Widget prev_focus=null;
private int pull_step = 0;
public int orig_x = 0;
public int orig_y = 0;
private int pull_w = 0;
private int pull_h = 0;
private int pull_x = 0;
private int pull_y = 0;
private int orig_h_tasks_notebook=0;
private int orig_w_tasks_notebook=0;
private int orig_h_main_vbox=0;
private int orig_w_main_vbox=0;
private int orig_monitor=-1;
private Xkb.State xkbstate;
public int position = 1;
public bool config_maximized=false;
public bool start_maximized=false;
public bool pull_maximized=false;
public bool temporary_maximized=false;
public bool allow_close=false;
public bool gravity_north_west=true;
public bool autohide=false;
public bool wayland=false;
private uint32 last_focus_out_event_time;
private unowned Gdk.Window ignore_last_active_window = null;
private DateTime on_monitors_changed_start_time = null;
public VTMainWindow(WindowType type) {
Object(type:type);
name="VTMainWindow";
}
construct {
this.title = "AltYo";
//this.border_width = 0;
this.skip_taskbar_hint = true;
this.urgency_hint = true;
this.set_decorated (false);
this.resizable = true;//we need resize!
this.set_has_resize_grip(false);//but hide grip
//this.set_focus_on_map (true);
//this.set_accept_focus (true);
//this.set_keep_above(true);
//this.stick ();
this.pixwin = new OffscreenWindow ();
this.pixwin.name="OffscreenWindow";
this.pixwin.show();
this.pixwin.damage_event.connect((event)=>{
if(this.visible && (this.pull_animation_active || this.pull_active)){
debug("pixwin.damage_event");
var w = this.get_window();
if(w!=null)
w.invalidate_rect(null,false);
}
});
//this.set_app_paintable(true);
//this.set_double_buffered(false);
//~ Gdk.RGBA c = Gdk.RGBA();
//~ c.parse("#000000");//black todo: make same color as vte
//~ c.alpha = 0.0;//transparency
this.set_visual (this.screen.get_rgba_visual ());//transparancy
this.set_app_paintable(true);//do not draw backgroud
//~ this.override_background_color(StateFlags.NORMAL, c);
//this.pixwin.set_visual (this.screen.get_rgba_visual ());//transparancy
//this.pixwin.set_app_paintable(true);//do not draw backgroud
}
public void CreateVTWindow(MySettings conf) {
this.conf=conf;
Image img = new Image.from_resource ("/org/gnome/altyo/altyo.svg");
this.set_icon(img.pixbuf);
this.keep_above=conf.get_boolean("keep_above_at_startup",this.keep_above);
if(!this.keep_above){
this.skip_taskbar_hint = false;
this.set_keep_above(false);
}
/* since VTE 2.91,
* needed for PanelHotkey to receive X.EventType.PropertyNotify events
* */
this.wayland = Gdk.Display.get_default().get_name().has_prefix("wayland");
if(!this.wayland){
var gdkwin = this.get_screen().get_root_window();
gdkwin.set_events(gdkwin.get_events()|Gdk.EventMask.PROPERTY_CHANGE_MASK);
this.hotkey = new PanelHotkey ();
this.hotkey.on_active_window_change.connect(this.check_focusout);
}
this.reconfigure();//window
this.not_configured=false;
this.ayobject= new AYObject(this,conf);
this.add(this.ayobject.main_vbox);
this.delete_event.connect (()=>{
if(this.allow_close==false){
this.ayobject.ShowQuitDialog();
return true;//prevent close
}
return false;//default is allow
});
this.destroy.connect (()=>{
this.hide();
if(!this.wayland){
this.hotkey.on_active_window_change.disconnect(this.check_focusout);
this.hotkey.unref();//destroy
}
this.ayobject.save_configuration();
this.conf.save();
unowned Gtk.Widget ch=this.pixwin.get_child();
if(ch is Gtk.Widget)
ch.destroy();
Gtk.main_quit();
});
this.conf.on_load.connect(()=>{
this.reconfigure();
if(this.current_state==WStates.VISIBLE){
this.configure_position();
this.update_position_size();
/*update maximize state according to config_maximized*/
if(!this.config_maximized && this.maximized){
this.maximized=false;
}else
if(this.config_maximized && !this.maximized){
this.maximized=true;
}
}
});
this.check_monitor_and_configure_position();
if(this.config_maximized && conf.get_boolean("start_hidden",false)){
this.ayobject.on_maximize(false);
this.maximized=true;
this.update_position_size(false);
}else{
this.update_position_size(false);
}
debug("CreateVTWindow end");
if(!this.conf.standalone_mode){
if ( conf.get_boolean("start_hidden",false) ){
this.pull_up();//all workarounds is inside pull_up,pull_down,update_position_size
this.pull_maximized=this.start_maximized;
}else{
this.show();
if(!this.start_maximized){
this.update_position_size();
}else{
this.maximized=true;
this.update_events();//process maximize event
}
this.window_set_active();
}
}else{
this.set_wmclass("altyo-tiling","Altyo");
this.set_decorated (true);
this.ayobject.on_maximize(false);
this.ayobject.on_maximize(true);
//this.update_position_size(false);
var should_be_h = this.ayobject.get_altyo_height(this.conf.standalone_mode);
this.set_default_size(this.ayobject.terminal_width,should_be_h);
this.show();
this.window_set_active();
}
GLib.Idle.add(this.ayobject.create_tabs);
if(!this.conf.standalone_mode){
unowned Gdk.Screen gscreen = this.get_screen ();
gscreen.monitors_changed.connect (()=>{
GLib.Timeout.add(1000,this.on_monitors_changed);//wait for some time until the monitor is configured
});
}
debug("end win show");
}
public bool on_monitors_changed(){
debug("gscreen.monitors_changed");
if(this.current_state == WStates.VISIBLE){
this.check_monitor_and_configure_position();//check if was attached window_default_monitor
if( this.configure_position() )
this.update_position_size();
}
return false; //stop the timer
}
private void check_monitor_and_configure_position(){
/* move window to appropriate monitor
* */
string? cfg_monitor = this.conf.get_string("window_default_monitor","");
if(cfg_monitor!=null && cfg_monitor!=""){
int x,y;
this.get_position (out x, out y);
unowned Gdk.Screen gscreen = this.get_screen ();
var current_monitor = gscreen.get_monitor_at_point (this.orig_x,this.orig_y);
var current_monitor_name = gscreen.get_monitor_plug_name (current_monitor);
if(current_monitor_name!=null && current_monitor_name!=cfg_monitor){
for(var i=0;i<gscreen.get_n_monitors ();i++){
if(gscreen.get_monitor_plug_name(i)==cfg_monitor){
debug("found monitor name %s",gscreen.get_monitor_plug_name (i));
Gdk.Rectangle rectangle;
this.orig_monitor=i;
rectangle=gscreen.get_monitor_workarea(i);
this.orig_x=rectangle.x+10;
var tmp=this.mouse_follow;
this.mouse_follow=false;
this.configure_position();
this.mouse_follow=tmp;
this.move(this.orig_x,this.orig_y);
return;//configured
}
}
}
}
/* mointor not found,
* use primary*/
this.configure_position();
}
private void save_current_monitor(int x,int y){
/* save position for current monitor
* */
unowned Gdk.Screen gscreen = this.get_screen ();
var current_monitor = gscreen.get_monitor_at_point (x,y);
if(this.orig_monitor!=current_monitor){
this.orig_monitor=current_monitor;
this.orig_x=x;
this.orig_y=y;
this.configure_position();
}
}
public void gdk_resize(int width,int height){
var window = this.get_window();
if(window!=null)
window.resize(width,height);
}
public bool on_pull_down(){
if(this.pull_step<this.pull_steps){
float arith_progress=( ((float)(1+this.pull_steps)/(float)2.0)*this.pull_steps);
int tmp =this.pull_steps-this.pull_step;
float arith_progress2=( ((float)(1+tmp)/(float)2.0)*(tmp));
uint h=(uint)(this.pull_h-(((float)this.pull_h)/arith_progress)*(arith_progress2) );
if(h == 0) h = 1;
//simple animation
//float step = ((float)this.pull_h/(float)this.pull_steps);
//uint h = (this.pull_h - (int)(step*(float)(this.pull_steps-this.pull_step)) )+1;
this.gdk_resize(this.pull_w,(int)h);
this.update_events();
//~ this.display_sync();
this.pull_step++;
return true;//continue animation
}else{
if(this.pull_step==this.pull_steps){
debug("on_pull_down last step %d",(int)this.maximized);
if(this.pull_maximized){
if(!this.maximized){
this.pull_update_maximize_size=true;
this.maximized=true;
}
}else{
this.gdk_resize(this.pull_w,pull_h);
}
this.update_events();
this.pull_step++;
return true;//continue animation
}
var ch=this.pixwin.get_child();//.reparent(this);//reparent from offscreen window
this.pixwin.remove(ch);
this.add(ch);
this.pull_animation_active=false;
this.pull_active=false;
this.current_state=WStates.VISIBLE;
debug("on_pull_down very last step");
this.update_position_size();
this.window_set_active();
X.Display display = new X.Display();
Xkb.lock_group(display, Xkb.UseCoreKbd, this.xkbstate.group);
return false;
}
}
public void pull_down(){
if(this.pull_animation_active || this.current_state!=WStates.HIDDEN)
return;
if(!this.animation_enabled ||
this.pixwin.get_child()==null){//prevent error if start hidden
this.configure_position();
this.resize (this.pull_w,this.pull_h);//start height
if((this.mouse_follow || !this.gravity_north_west) && !this.pull_maximized){
this.move (this.orig_x,this.orig_y);//new position
}else
if(this.gravity_north_west)
this.move (this.pull_x,this.pull_y);
else
this.move (this.pull_x,this.orig_y);
this.show();
debug("pull_down pull_maximized=%d",(int)this.pull_maximized);
if(this.pull_maximized)
this.maximized=true;
this.current_state=WStates.VISIBLE;
this.update_position_size(false);//reset size to -1
this.window_set_active();
//this.queue_draw();//fix some draw problems (when mouse inside hvbox after show?).
this.pull_active=false;
return;
}
this.pull_animation_active=true;
if(!this.pull_maximized)
this.configure_position();
this.set_default_size(this.pull_w,2);//Default size - used only the FIRST time we map a window
this.gdk_resize(this.pull_w,2);//Default size - used only the FIRST time we map a window
//~ this.display_sync();
this.current_state=WStates.VISIBLE;
this.window_set_active();//update keep_above stick and focus
if((this.mouse_follow || !this.gravity_north_west) && !this.pull_maximized){
this.move (this.orig_x,this.orig_y);//new position
}else
if(this.gravity_north_west)
this.move (this.pull_x,this.pull_y);
else
this.move (this.pull_x,this.orig_y);
//~ this.display_sync();
if (this.pull_w >1 && this.pull_h >1)
this.pull_step=0;
else
this.pull_step=this.pull_steps;//skip animation
this.show();
GLib.Timeout.add_full(GLib.Priority.LOW,this.animation_speed,this.on_pull_down);
}
public bool on_pull_up(){
if(this.pull_step<this.pull_steps){
float arith_progress=( ((float)(1+this.pull_steps)/(float)2.0)*this.pull_steps);
int tmp =this.pull_steps-this.pull_step;
float arith_progress2=( ((float)(this.pull_steps+tmp)/(float)2.0)*this.pull_step);
uint h=(uint)(this.pull_h-((float)this.pull_h/arith_progress)*(arith_progress2) );
if(h == 0) h = 1;
//simple animation
//float step = ((float)this.pull_h/(float)this.pull_steps);
//uint h = (this.pull_h - (int)(step*(float)this.pull_step) )+1;
/* object Gdk.Window have option "state" with current window state
* we will check is window still in fullscreen satate*/
this.fullscreened=false;//force unfullscreen, some WMs sets fullscreen state if window size equal to fullscreen
this.gdk_resize(this.pull_w,(int)h);
this.update_events();
//~ this.display_sync();
this.pull_step++;
return true;//continue animation
}else{
this.hide();
//~ this.unrealize();//important!
this.current_state=WStates.HIDDEN;
this.pull_animation_active=false;
return false;
}
}
public void pull_up(){
if(this.pull_animation_active || this.current_state!=WStates.VISIBLE)
return;
this.pull_h=this.get_allocated_height();
this.pull_w=this.get_allocated_width();
this.get_position (out this.pull_x, out this.pull_y);
this.prev_focus=this.get_focus();
debug("pull_up orig_h=%d orig_w=%d",this.pull_h,this.pull_w);
this.orig_h_main_vbox = this.ayobject.main_vbox.get_allocated_height();
this.orig_w_main_vbox = this.ayobject.main_vbox.get_allocated_width();
this.orig_h_tasks_notebook = this.ayobject.tasks_notebook.get_allocated_height();
this.orig_w_tasks_notebook = this.ayobject.tasks_notebook.get_allocated_width();
debug("pull_up orig_h_tasks_notebook=%d orig_w_tasks_notebook=%d",orig_h_tasks_notebook,orig_w_tasks_notebook);
this.pull_maximized=this.maximized;
X.Display display = new X.Display();
Xkb.get_state(display, Xkb.UseCoreKbd, out this.xkbstate);
if(this.pull_w<2 || this.pull_h<2){//if start hidden
//we don't know size , guess
this.orig_w_tasks_notebook=orig_w_main_vbox=this.pull_w=this.ayobject.terminal_width;
this.orig_h_tasks_notebook=orig_h_main_vbox=this.pull_h=this.ayobject.terminal_height;
}
this.save_current_monitor(this.pull_x,this.pull_y);
if(!this.animation_enabled){
this.pull_active=true;
this.ayobject.clear_prelight_state();
this.prev_focus=this.get_focus();
/* BUG:#16
* When unhide Altyo, it doesn`t respect setting of layout for each window (not global)...
* core problem:
* 1) xwindow have only NormalState|IconicState|WithdrawnState(unmaped)
* 2) libwnck sends "window-closed" signal for unmaped window
* 3) xfce4-xkb-plugin remove windowid from internal list as it think window is closed
* chain is follow:
* window.hide()->WithdrawnState->Unmap->libwnck=>"window-closed"->xfce4-xkb-plugin = forgot window keyboard layout.
* same problem in gnome3.
* as workarund for that we are using window.iconify(),
* as drawbacks, some window managers will show minimization animations (i.e. metacity)
* seems that this is fundamental Xwindow/window_managers problem.
* */
this.hide();
//~ this.unrealize();//important!
this.current_state=WStates.HIDDEN;
return;
}
this.pull_active=true;
this.height_request=-1;//allow main window resize
//debug("reparent to offscreen window");
//this.get_child().reparent(this.pixwin);//reparent to offscreen window
var ch=this.get_child();//.reparent(this);//reparent from offscreen window
this.pixwin.set_size_request(pull_w,pull_h);
var w = this.get_window();
if(w!=null)
this.get_window().freeze_toplevel_updates_libgtk_only();
this.remove(ch);
this.pixwin.add(ch);
if(w!=null)
this.get_window().thaw_toplevel_updates_libgtk_only();
//set main_vbox size same as original,otherwise draw will be broken
this.ayobject.main_vbox.height_request = this.orig_h_main_vbox;
this.ayobject.main_vbox.width_request = this.orig_w_main_vbox;
//debug("end reparent to offscreen window");
if(this.maximized){
//set main_vbox size after unmaximize
this.width_request=this.pull_w;
this.height_request=this.pull_h;
this.check_resize();//container
this.pull_w-=2;//reduce size a little, prevent move to another monitor in some cases
this.pull_h-=2;
this.maximized=false;
this.move(this.pull_x,this.pull_y);
}else
this.check_resize();
//debug("pull_up 0-%d this.get_allocated_height=%d this.orig_h=%d",this.get_allocated_height()-this.pull_h, this.get_allocated_height(),this.pull_h);
//debug("pull_up orig_h=%d orig_w=%d",this.pull_h,this.pull_w);
if (this.get_allocated_height()>1)
this.pull_step=0;
else
this.pull_step=this.pull_steps;//skip animation
this.pull_animation_active=true;
this.ayobject.clear_prelight_state();
this.update_events();//process pixwin.damage_event
GLib.Timeout.add_full(GLib.Priority.LOW,this.animation_speed,this.on_pull_up);
}
/*public void fake_pullup(){
* according to user settings
* setup pixwin size,
* setup main_vbox size,
* setup tasks_notebook,
* setup all nesessary variables for pull down
* reparent to pix win
* Think, is it worth it? }*/
public void toggle_window(){
debug("toggle_window start");
if(this.pull_animation_active || this.conf.standalone_mode) return;
/* when hotkey is pressed, main window loose focus,
* so impossible to check, is windows focused or not.
* as workaround, remember last focus-out time,
* if it more than 100ms, then window was unfocused
* */
if(!this.wayland){
X.Window w=this.hotkey.get_input_focus();
var slf_win=this.get_window();
if(slf_win!=null)
debug("slf=%d w=%d",(int)Gdk.X11Window.get_xid(slf_win),(int)w);
//debug("toggle_window %d %d",(int)this.last_event_time,(int)this.hotkey.last_focus_out_event_time);
//&& !this.is_active && (this.current_state == WStates.VISIBLE) && ((int)this.hotkey.last_key_event_time-(int)this.last_focus_out_event_time)>100
if(this.current_state==WStates.VISIBLE && !this.keep_above && slf_win!=null && Gdk.X11Window.get_xid(slf_win) != w ){
this.window_set_active();
return;
}
}
if(this.current_state == WStates.HIDDEN)
this.pull_down();
else
this.pull_up();
debug("toggle_window end");
}
public override bool window_state_event (Gdk.EventWindowState event){
//~ public bool window_state_event2 (Gdk.EventWindowState event){
//~ debug("window_state_event type=%d new_state=%d mask=%d",(int)event.type,(int)event.new_window_state,(int)event.changed_mask);
var ret=base.window_state_event(event);
debug("window_state_event !!!!!!!!! this.maximized=%d event.changed_mask=%d",(int)this.maximized,event.changed_mask);
//ignore maximize event when pull active
if( (event.changed_mask & Gdk.WindowState.FULLSCREEN)==Gdk.WindowState.FULLSCREEN ){//maximize state change
debug("changed_mask FULLSCREEN");
if(!this.pull_active && !this.pull_animation_active && !this.conf.standalone_mode){
if( (this.my_window_state & MYWINStates.MAXIMIZED) != MYWINStates.MAXIMIZED)
this.maximized = false;//some WMs set FULLSCREEN flag when window maximized
}
}
if( (event.changed_mask & Gdk.WindowState.MAXIMIZED)==Gdk.WindowState.MAXIMIZED ){//maximize state change
this.wait_window_manager=false;
if(!this.pull_active && !this.pull_animation_active && !this.conf.standalone_mode){
if((Gdk.WindowState.MAXIMIZED & event.new_window_state)== Gdk.WindowState.MAXIMIZED){//maximize
debug("new state maximize");
this.my_window_state |= MYWINStates.MAXIMIZED;
this.update_position_size();
}else{//unmaximize
debug("new state unmaximize");
this.my_window_state &= ~MYWINStates.MAXIMIZED;
this.configure_position();
this.update_position_size();
}
}
}
if( (event.changed_mask & Gdk.WindowState.ICONIFIED)==Gdk.WindowState.ICONIFIED ){//ICONIFIED state change
debug("changed_mask ICONIFIED");
if((event.new_window_state & Gdk.WindowState.ICONIFIED)!=Gdk.WindowState.ICONIFIED){
//deiconify from window manager
this.pull_down();
}
}
return ret;
//false;//continue
//base.window_state_event(event);
}
public override bool configure_event(Gdk.EventConfigure event){
//~ debug("configure_event");
//~ debug("event.type=%d window=%d x=%d y=%d width=%d height=%d",event.type,(int)event.window,event.x,event.y,event.width,event.height);
var ret=base.configure_event(event);
if(this.allow_update_size && this.wait_for_window_position_update>0){
if(this.update_position_size_for_glib_timer_id == 0)
this.update_position_size_for_glib_timer_id=GLib.Idle.add_full(GLib.Priority.DEFAULT_IDLE,this.update_position_size_for_glib);//recheck position after 50ms
return ret;
}
/*update position and size when window has moved to another monitor*/
if(this.allow_update_size){
unowned Gdk.Screen gscreen = this.get_screen ();
int current_monitor = gscreen.get_monitor_at_point (event.x,event.y);
if(this.orig_monitor != current_monitor){
debug("configure_event monitor changed");
/*event on monitor changed*/
/* if window was dragged by mouse, then window_resize and window_move will not working until user release mouse button
* we don't have resize/move events, so we do not know when the user is finished moving
*/
this.on_monitors_changed_start_time = new DateTime.now_local();
if(this.on_monitor_changed_force_new_position_glib_timer_id != 0)
GLib.Source.remove(this.on_monitor_changed_force_new_position_glib_timer_id);
this.on_monitor_changed_force_new_position_glib_timer_id=GLib.Timeout.add(500,this.on_monitor_changed_force_new_position);//every 0.5s
}
}
return ret;
}
public bool on_monitor_changed_force_new_position(){
debug("on_monitor_changed_force_new_position");
int x,y;
this.get_position (out x, out y);
if(!this.allow_update_size)
return false; //stop
if(this.orig_x == x && this.orig_y == y)
return false; //stop
this.orig_x=x;//set coordinates in new monitor
this.orig_y=y;//set coordinates in new monitor
this.configure_position();//configure position for new monitor
var now = new DateTime.now_local();
TimeSpan tdelta = now.difference(this.on_monitors_changed_start_time);
if(x!=this.orig_x && tdelta < (1000000*30) && this.allow_update_size){ //timeout 30 seconds
this.update_position_size();
return true; //continue
}else{
if(this.on_monitor_changed_force_new_position_glib_timer_id>0)
this.on_monitor_changed_force_new_position_glib_timer_id=0;
return false; //stop
}
}
public override bool focus_out_event (Gdk.EventFocus event) {
if(!this.wayland){
this.last_focus_out_event_time=Gdk.x11_get_server_time(this.get_window());
}
return base.focus_out_event (event);
}
private void check_focusout(){
debug("check_focusout focus=%d state=%d",(int)this.has_toplevel_focus,(int)this.current_state);
if( !this.has_toplevel_focus &&
this.autohide &&
!this.pull_active &&
this.current_state==WStates.VISIBLE ){
var slf_win=this.get_window();
if(slf_win!=null){
if(!this.wayland){
X.Window w=this.hotkey.get_input_focus();
X.Window slf_xid = Gdk.X11Window.get_xid(slf_win);
debug("active_window4 slf=%x focus=%x",(int)slf_xid,(int)w);
if(slf_xid!=w){
X.Window transient = this.hotkey.get_transient_for_xid(w);
debug("active_window5 slf=%x transient_for=%x",(int)slf_xid,(int)transient);
if(transient!=slf_xid)//include transient==0
this.pull_up();//not exist,hide
}
}//not wayland
}
}
}
public override bool draw (Cairo.Context cr){
if(this.pull_animation_active || this.pull_active){
cr.save();
//debug("draw 0-%d this.get_allocated_height=%d this.orig_h=%d",this.get_allocated_height()-this.pull_h, this.get_allocated_height(),this.pull_h);
var surf=this.pixwin.get_surface();
if(surf!=null){
cr.set_source_surface(surf,0,this.get_allocated_height()-this.pull_h);
cr.paint();
cr.stroke ();
}else
base.draw(cr);
cr.restore();
return false;
}else{
return base.draw(cr);
}
}
public void update_events(){
while (Gtk.events_pending ()){
Gtk.main_iteration ();
}
Gdk.flush();
}
public void display_sync(){
var window = this.get_window();
if(window!=null){
window.get_display().sync();
}
}
public void reconfigure(){
debug("reconfigure VTWindow");
if(this.conf.reduce_memory_usage){
var settings = Gtk.Settings.get_default();
settings.gtk_menu_images=false;
settings.gtk_button_images=false;
settings.gtk_enable_animations=false;
settings.gtk_toolbar_style=Gtk.ToolbarStyle.TEXT;
}
//update on reset
conf.get_boolean("keep_above_at_startup",true);
conf.get_boolean("start_hidden",false);
conf.get_string("window_default_monitor","");
this.allow_close=!conf.get_boolean("confirm_to_quit",true);
var css_main = new CssProvider ();
//~ string style_str= ""+
//~ ".window_maximized AYTerm{-AYTerm-bg-color: alpha(#000000,1.0);}"+
//~ "AYTerm{ -AYTerm-bg-color: alpha(#000000,1.0); -AYTerm-fg-color: #00FFAA; -AYTerm-palette-0:#FF0000; -AYTerm-palette-1:#AA0000; -AYTerm-palette-2:#00AA00; -AYTerm-palette-3:#AA5500; -AYTerm-palette-4:#0000AA; -AYTerm-palette-5:#AA00AA; -AYTerm-palette-6:#00AAAA; -AYTerm-palette-7:#AAAAAA; -AYTerm-palette-8:#555555; -AYTerm-palette-9:#FF5555; -AYTerm-palette-10:#55FF55; -AYTerm-palette-11:#FFFF55; -AYTerm-palette-12:#5555FF; -AYTerm-palette-13:#FF55FF; -AYTerm-palette-14:#55FFFF; -AYTerm-palette-15:#FFFFFF; } " +
//~ "VTToggleButton GtkLabel { font: Mono 10; -GtkWidget-focus-padding: 0px; -GtkButton-default-border:0px; -GtkButton-default-outside-border:0px; -GtkButton-inner-border:0px; border-width:0px; -outer-stroke-width: 0px; margin:0px; padding:0px;}"+
//~ "VTToggleButton {-GtkWidget-focus-padding: 0px;-GtkButton-default-border:0px;-GtkButton-default-outside-border:0px;-GtkButton-inner-border:0px;border-color:alpha(#000000,0.0);border-width: 1px;-outer-stroke-width: 0px;border-radius: 3px;border-style: solid;background-image: none;margin:0px;padding:0px 0px 0px 0px;background-color: alpha(#000000,0.0);color: #AAAAAA; box-shadow: none;}"+
//~ "VTToggleButton:active{background-color: #00AAAA;background-image: -gtk-gradient(radial,center center, 0,center center, 1, from (#00BBBB),to (#008888) );color: #000000;}"+
//~ "VTToggleButton:prelight {background-color: #AAAAAA;background-image: -gtk-gradient(radial,center center, 0,center center, 1, from (#AAAAAA),to (#777777) ); color: #000000;}"+
//~ "VTToggleButton:active:prelight{background-color: #00AAAA;background-image: -gtk-gradient(radial,center center, 0,center center, 1, from (lighter(#00BBBB)),to (#008888) );color: #000000;}"+
//~ "VTToggleButton *:selected{ background-color: alpha(#FF0000, 0.4);background-image: none;}"+
//~ ".window_multitabs {border-width: 2px 2px 0px 2px;border-color: #3C3B37;border-style: solid;padding:0px;margin:0;}"+
//~ ".window_single_tab {border-width: 2px 2px 2px 2px;border-color: #3C3B37;border-style: solid;}"+
//~ "#terms_notebook {border-width: 0px;border-style: solid;padding:0px;margin:0;}"+
//~ "#search_hbox :active { border-color: @fg_color; color: #FF0000;}"+
//~ "#search_hbox :prelight { background-color: alpha(#000000,0.0); border-color: @fg_color; color: #FF0000;}"+
//~ "#search_hbox {border-width: 0px 0px 0px 0px; -outer-stroke-width: 0px; border-radius: 0px 0px 0px 0px; border-style: solid; background-image: none; margin:0px; padding:0px 0px 1px 0px; background-color: #000000; border-color: @bg_color; color: #00FFAA;}"+
//~ "HVBox {border-width: 0px 2px 2px 2px; border-color: #3C3B37;border-style: solid; background-color: #000000;}"+
//~ "#OffscreenWindow, VTMainWindow,#HVBox_dnd_window {border-width: 0px; border-style: solid; background-color: alpha(#000000,0.1);}"+
//~ "HVBox,#quick_options_notebook{background-color: alpha(#000000,1.0);}"+
//~ "#settings-scrolledwindow{ background-color: @bg_color;}"+
//~ "";
string style_str=settings_base_css;
string style_str_extra="";
if(Gtk.get_major_version()>=3 && Gtk.get_minor_version()>4)
style_str_extra+= " VTToggleButton{transition-duration: 0s;}";
if(Gtk.get_major_version()>=3 && Gtk.get_minor_version()>8)
style_str_extra+= " #VTToggleButton, #VTToggleButton .label { outline-offset: 0px; } ";//gtk 3.20
else
style_str_extra+= " #VTToggleButton, #VTToggleButton .label { -GtkWidget-focus-padding: 0px; -GtkButton-default-border:0px; -GtkButton-default-outside-border:0px; -GtkButton-inner-border:0px; background-image: none; box-shadow: none; -outer-stroke-width: 0px;} ";
//~ if(Gtk.get_major_version()>=3 && Gtk.get_minor_version()>6)//special eyecandy if supported ;)
//~ style_str+= "VTToggleButton:active { text-shadow: 1px 1px 2px #005555;}";
//prevent transparency of window background in standalone mode
if(conf.standalone_mode)
style_str_extra+= " #OffscreenWindow.*, VTMainWindow ,VTMainWindow > *,#HVBox_dnd_window {background-color: alpha(#000000,1.0);}";
//todo: bad performance on pull_up. when tab state is prelight then, on every animation step happens recursive size recalculation
//style_str+= "VTToggleButton { transition: 400ms ease-in-out;} VTToggleButton:active { transition: 0ms ease-in-out;text-shadow: 1px 1px 2px #005555;} VTToggleButton:prelight {transition: 0ms ease-in-out;}";
css_main.parsing_error.connect((section,error)=>{
debug("css_main.parsing_error %s line:%d pos:%d",error.message,(int)section.get_end_line(),(int)section.get_end_position());
});
try{
css_main.load_from_data (style_str+this.conf.get_string("program_style",settings_css_linux+style_str_extra),-1);
Gtk.StyleContext.add_provider_for_screen(this.get_screen(),css_main,Gtk.STYLE_PROVIDER_PRIORITY_USER);
}catch (Error e) {
debug("Theme error! loading default..");
try{
css_main.load_from_data (style_str,-1);
Gtk.StyleContext.add_provider_for_screen(this.get_screen(),css_main,Gtk.STYLE_PROVIDER_PRIORITY_USER);
}catch (Error e) {
debug("Theme error! default theme is broken!");
}
}
this.animation_enabled=conf.get_boolean("animation_enabled",true);
this.pull_steps=conf.get_integer("animation_pull_steps",10,(ref new_val)=>{
if(new_val<1){new_val=10;return CFG_CHECK.REPLACE;}
return CFG_CHECK.OK;
});
if( !this.wayland ){
this.hotkey.unbind();
if(!this.conf.disable_hotkey){
KeyBinding grave=this.hotkey.bind (this.conf.get_accel_string("main_hotkey","<Alt>grave"));
if(grave!=null)
grave.on_trigged.connect(this.toggle_window);
else{
var new_key = this.conf.get_accel_string("main_hotkey","<Alt>grave");
do{
new_key = this.ShowGrabKeyDialog(new_key);
if(this.ayobject!=null && this.ayobject.action_group!=null){
/*update main_hotkey on reset*/
var action = this.ayobject.action_group.get_action("main_hotkey");
if(action!=null){
uint accelerator_key;
Gdk.ModifierType accelerator_mods;
Gtk.accelerator_parse(new_key,out accelerator_key,out accelerator_mods);
if(accelerator_key!=0){
if(this.ayobject.update_action_keybinding(action,accelerator_key,accelerator_mods))
grave=this.hotkey.bind (new_key);//if new_key is not used for other actions then, try to bind
}
}
}else{
grave=this.hotkey.bind (new_key);//currently we have no actions, try to bind
}
}while(grave==null && !this.allow_close);
if(this.allow_close) return;//possible on destroying
this.conf.set_accel_string("main_hotkey",new_key);
grave.on_trigged.connect(this.toggle_window);
}
}else{
this.conf.get_accel_string("main_hotkey","<Alt>grave");//just read option
}
}//not wayland
this.mouse_follow = conf.get_boolean("follow_the_white_rabbit",false);
this.gravity_north_west = conf.get_boolean("window_gravity_north_west",true);
if(this.gravity_north_west)
this.gravity=Gdk.Gravity.NORTH_WEST;
else
this.gravity=Gdk.Gravity.SOUTH_WEST;
this.autohide = conf.get_boolean("window_autohide",false);
}//reconfigure
public bool configure_position(){