@@ -10,7 +10,7 @@ import * as a from 'arena';
10
10
import * as utils from 'utils' ;
11
11
12
12
const Arena = a . Arena ;
13
- const { St } = imports . gi ;
13
+ const { Clutter , GObject , St } = imports . gi ;
14
14
15
15
const ACTIVE_TAB = 'pop-shell-tab pop-shell-tab-active' ;
16
16
const INACTIVE_TAB = 'pop-shell-tab pop-shell-tab-inactive' ;
@@ -42,6 +42,78 @@ function stack_widgets_new(): StackWidgets {
42
42
return { tabs } ;
43
43
}
44
44
45
+ const ContainerButton = GObject . registerClass ( {
46
+ Signals : { 'activate' : { } } ,
47
+ } , class ImageButton extends St . Button {
48
+ _init ( icon : St . Icon ) {
49
+ super . _init ( {
50
+ child : icon ,
51
+ x_expand : true ,
52
+ y_expand : true ,
53
+ } )
54
+ }
55
+ } )
56
+
57
+ interface TabButton extends St . Button {
58
+ set_title : ( title : string ) => void ;
59
+ }
60
+
61
+ const TabButton = GObject . registerClass ( {
62
+ Signals : { 'activate' : { } } ,
63
+ } , class TabButton extends St . Button {
64
+ _init ( window : ShellWindow ) {
65
+ const icon = window . icon ( window . ext , 24 )
66
+ icon . set_x_align ( Clutter . ActorAlign . START )
67
+
68
+ const label = new St . Label ( {
69
+ y_expand : true ,
70
+ x_align : Clutter . ActorAlign . START ,
71
+ y_align : Clutter . ActorAlign . CENTER ,
72
+ style : "padding-left: 8px"
73
+ } )
74
+
75
+ label . text = window . title ( )
76
+
77
+ const container = new St . BoxLayout ( {
78
+ y_expand : true ,
79
+ y_align : Clutter . ActorAlign . CENTER ,
80
+ } )
81
+
82
+ const close_button = new ContainerButton ( new St . Icon ( {
83
+ icon_name : 'window-close-symbolic' ,
84
+ icon_size : 24 ,
85
+ y_align : Clutter . ActorAlign . CENTER ,
86
+ } ) )
87
+
88
+ close_button . connect ( 'clicked' , ( ) => {
89
+ window . meta . delete ( global . get_current_time ( ) )
90
+ } )
91
+
92
+ close_button . set_x_align ( Clutter . ActorAlign . END )
93
+ close_button . set_y_align ( Clutter . ActorAlign . CENTER )
94
+
95
+ container . add_actor ( icon )
96
+ container . add_actor ( label )
97
+ container . add_actor ( close_button )
98
+
99
+ super . _init ( {
100
+ child : container ,
101
+ x_expand : true ,
102
+ y_expand : true ,
103
+ y_align : Clutter . ActorAlign . CENTER ,
104
+ } )
105
+
106
+
107
+ this . _title = label
108
+ }
109
+
110
+ set_title ( text : string ) {
111
+ if ( this . _title ) {
112
+ this . _title . text = text
113
+ }
114
+ }
115
+ } )
116
+
45
117
export class Stack {
46
118
ext : Ext ;
47
119
@@ -60,7 +132,7 @@ export class Stack {
60
132
61
133
workspace : number ;
62
134
63
- buttons : a . Arena < St . Button > = new Arena ( ) ;
135
+ buttons : a . Arena < TabButton > = new Arena ( ) ;
64
136
65
137
tabs_height : number = TAB_HEIGHT ;
66
138
@@ -95,15 +167,9 @@ export class Stack {
95
167
if ( ! this . widgets ) return ;
96
168
97
169
const entity = window . entity ;
98
- const label = window . title ( )
99
170
const active = Ecs . entity_eq ( entity , this . active ) ;
100
171
101
- const button : St . Button = new St . Button ( {
102
- label,
103
- x_expand : true ,
104
- style_class : active ? ACTIVE_TAB : INACTIVE_TAB
105
- } ) ;
106
-
172
+ const button = new TabButton ( window )
107
173
const id = this . buttons . insert ( button ) ;
108
174
109
175
let tab : Tab = { active, entity, signals : [ ] , button : id , button_signal : null } ;
@@ -443,7 +509,7 @@ export class Stack {
443
509
}
444
510
445
511
this . watch_signals ( this . active_id , c . button , window ) ;
446
- this . buttons . get ( c . button ) ?. set_label ( window . title ( ) ) ;
512
+ this . buttons . get ( c . button ) ?. set_title ( window . title ( ) ) ;
447
513
this . activate ( window . entity ) ;
448
514
}
449
515
}
@@ -598,7 +664,7 @@ export class Stack {
598
664
this . tabs [ comp ] . signals = [
599
665
window . meta . connect ( 'notify::title' , ( ) => {
600
666
this . window_exec ( comp , entity , ( window ) => {
601
- this . buttons . get ( button ) ?. set_label ( window . title ( ) )
667
+ this . buttons . get ( button ) ?. set_title ( window . title ( ) )
602
668
} ) ;
603
669
} ) ,
604
670
0 commit comments