@@ -89,18 +89,19 @@ class XpraWindow {
8989 this . minimized = false ;
9090 this . maximized = false ;
9191 this . focused = false ;
92- this . decorations = true ;
92+ this . decorations = true ; // whether the window should be decorated or not
93+ this . decorated = true ; // whether it actually is (fullscreen windows are not)
9394 this . resizable = false ;
9495 this . stacking_layer = 0 ;
9596
9697 // Icon cache
9798 this . icon = null ;
9899
99100 // get offsets
100- this . leftoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-left-width" ) , 10 ) ;
101- this . rightoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-right-width" ) , 10 ) ;
102- this . topoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-top-width" ) , 10 ) ;
103- this . bottomoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-bottom-width" ) , 10 ) ;
101+ this . leftoffset = 0 ;
102+ this . rightoffset = 0 ;
103+ this . topoffset = 0 ;
104+ this . bottomoffset = 0 ;
104105
105106 // update metadata that is safe before window is drawn
106107 this . update_metadata ( metadata , true ) ;
@@ -129,7 +130,24 @@ class XpraWindow {
129130 this . resizable = true ;
130131 }
131132
132- this . add_window_decorations ( ) ;
133+ this . configure_border_class ( ) ;
134+ this . add_headerbar ( ) ;
135+ this . make_draggable ( )
136+ this . update_offsets ( )
137+
138+ // stop propagation if we're over the window:
139+ jQuery ( this . div ) . mousedown ( ( e ) => e . stopPropagation ( ) ) ;
140+ //bug 2418: if we stop 'mouseup' propagation,
141+ //jQuery can't ungrab the window with Firefox
142+ // assign callback to focus window if header is clicked.
143+ jQuery ( this . d_header ) . click ( ( e ) => {
144+ if (
145+ ! this . minimized &&
146+ $ ( e . target ) . parents ( ".windowbuttons" ) . length === 0
147+ ) {
148+ this . focus ( ) ;
149+ }
150+ } ) ;
133151
134152 // create the spinner overlay div
135153 jQuery ( this . div ) . prepend (
@@ -167,24 +185,34 @@ class XpraWindow {
167185 }
168186
169187 configure_border_class ( ) {
170- if ( this . resizable || this . decorations ) {
188+ if ( this . resizable || this . decorated ) {
171189 jQuery ( this . div ) . addClass ( "border" ) ;
172190 }
173191 else {
174192 jQuery ( this . div ) . removeClass ( "border" ) ;
175193 }
176194 }
177195
196+ update_offsets ( ) {
197+ this . leftoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-left-width" ) , 10 ) ;
198+ this . rightoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-right-width" ) , 10 ) ;
199+ this . topoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-top-width" ) , 10 )
200+ this . bottomoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-bottom-width" ) , 10 ) ;
201+ if ( this . decorated ) {
202+ this . topoffset = this . topoffset + Number . parseInt ( jQuery ( this . d_header ) . css ( "height" ) , 10 ) ;
203+ }
204+ console . log ( "decorated=" , this . decorated , "offsets=" , [ this . leftoffset , this . topoffset , this . rightoffset , this . bottomoffset ] ) ;
205+ }
206+
207+
178208 add_headerbar ( ) {
179209 const wid = this . wid ;
180210 // add a title bar to this window if we need to
181211 // create header
182212 let head =
183213 `<div id="head${ wid } " class="windowhead"> ` +
184214 `<span class="windowicon"><img alt="window icon" class="windowicon" id="windowicon${ wid } " /></span> ` +
185- `<span class="windowtitle" id="title${ wid } ">${
186- this . title
187- } </span> ` +
215+ `<span class="windowtitle" id="title${ wid } ">${ this . title } </span> ` +
188216 `<span class="windowbuttons"> ` ;
189217 if ( ! jQuery ( this . div ) . hasClass ( "modal" ) ) {
190218 //modal windows cannot be minimized (see #204)
@@ -201,6 +229,29 @@ class XpraWindow {
201229 this . focus ( ) ;
202230 }
203231 } ) ;
232+ this . d_header = `#head${ wid } ` ;
233+ this . d_closebtn = `#close${ wid } ` ;
234+ this . d_maximizebtn = `#maximize${ wid } ` ;
235+ this . d_minimizebtn = `#minimize${ wid } ` ;
236+
237+ if ( this . resizable ) {
238+ this . make_resizable ( ) ;
239+ jQuery ( this . d_header ) . dblclick ( ( ) => this . toggle_maximized ( ) ) ;
240+ jQuery ( this . d_closebtn ) . click ( ( ) => this . window_closed_cb ( this ) ) ;
241+ jQuery ( this . d_maximizebtn ) . click ( ( ) => this . toggle_maximized ( ) ) ;
242+ jQuery ( this . d_minimizebtn ) . click ( ( ) => this . toggle_minimized ( ) ) ;
243+ } else {
244+ jQuery ( this . d_maximizebtn ) . hide ( ) ;
245+ jQuery ( `#windowlistitemmax${ wid } ` ) . hide ( ) ;
246+ }
247+
248+ // we must set a sensible default early
249+ // so geometry calculations have the correct offset:
250+ if ( ! ( "decorations" in this . metadata ) ) {
251+ const decorated = ! this . override_redirect && this . windowtype !== "DROPDOWN" && this . windowtype !== "TOOLTIP" && this . windowtype !== "POPUP_MENU" && this . windowtype !== "MENU" && this . windowtype !== "COMBO" ;
252+ this . _set_decorated ( decorated ) ;
253+ console . log ( "decorated=" , decorated , "windowtype=" , this . windowtype ) ;
254+ }
204255 }
205256
206257 make_draggable ( ) {
@@ -253,44 +304,6 @@ class XpraWindow {
253304 } ) ;
254305 }
255306
256- add_window_decorations ( ) {
257- const wid = this . wid ;
258- this . configure_border_class ( ) ;
259- this . add_headerbar ( ) ;
260- this . make_draggable ( )
261- if ( this . resizable ) {
262- this . make_resizable ( ) ;
263- }
264- this . d_header = `#head${ wid } ` ;
265- this . d_closebtn = `#close${ wid } ` ;
266- this . d_maximizebtn = `#maximize${ wid } ` ;
267- this . d_minimizebtn = `#minimize${ wid } ` ;
268- if ( this . resizable ) {
269- jQuery ( this . d_header ) . dblclick ( ( ) => this . toggle_maximized ( ) ) ;
270- jQuery ( this . d_closebtn ) . click ( ( ) => this . window_closed_cb ( this ) ) ;
271- jQuery ( this . d_maximizebtn ) . click ( ( ) => this . toggle_maximized ( ) ) ;
272- jQuery ( this . d_minimizebtn ) . click ( ( ) => this . toggle_minimized ( ) ) ;
273- } else {
274- jQuery ( this . d_maximizebtn ) . hide ( ) ;
275- jQuery ( `#windowlistitemmax${ wid } ` ) . hide ( ) ;
276- }
277- // adjust top offset
278- this . topoffset = this . topoffset + Number . parseInt ( jQuery ( this . d_header ) . css ( "height" ) , 10 ) ;
279- // stop propagation if we're over the window:
280- jQuery ( this . div ) . mousedown ( ( e ) => e . stopPropagation ( ) ) ;
281- //bug 2418: if we stop 'mouseup' propagation,
282- //jQuery can't ungrab the window with Firefox
283- // assign callback to focus window if header is clicked.
284- jQuery ( this . d_header ) . click ( ( e ) => {
285- if (
286- ! this . minimized &&
287- $ ( e . target ) . parents ( ".windowbuttons" ) . length === 0
288- ) {
289- this . focus ( ) ;
290- }
291- } ) ;
292- }
293-
294307 init_canvas ( ) {
295308 this . canvas = null ;
296309 jQuery ( this . div ) . find ( "canvas" ) . remove ( ) ;
@@ -446,7 +459,7 @@ class XpraWindow {
446459 this . x = Math . min ( oldx , ww - min_w_visible ) ;
447460 }
448461 if ( oldy <= this . topoffset && oldy <= min_h_visible ) {
449- this . y = Number . parseInt ( this . topoffset ) ;
462+ this . y = this . topoffset ;
450463 } else if ( oldy >= wh - min_h_visible ) {
451464 this . y = Math . min ( oldy , wh - min_h_visible ) ;
452465 }
@@ -628,7 +641,7 @@ class XpraWindow {
628641 this . windowtype = Utilities . s ( metadata [ "window-type" ] [ 0 ] ) ;
629642 }
630643 if ( "decorations" in metadata ) {
631- this . decorations = metadata [ "decorations" ] ;
644+ this . decorations = Boolean ( metadata [ "decorations" ] ) ;
632645 this . _set_decorated ( this . decorations ) ;
633646 this . updateCSSGeometry ( ) ;
634647 this . handle_resized ( ) ;
@@ -693,7 +706,7 @@ class XpraWindow {
693706 }
694707 let hdec = 0 ;
695708 const wdec = 0 ;
696- if ( this . decorations ) {
709+ if ( this . decorated ) {
697710 //adjust for header
698711 hdec = jQuery ( `#head${ this . wid } ` ) . outerHeight ( true ) ;
699712 }
@@ -879,20 +892,18 @@ class XpraWindow {
879892 }
880893
881894 _set_decorated ( decorated ) {
882- this . topoffset = Number . parseInt ( jQuery ( this . div ) . css ( "border-top-width" ) , 10 ) ;
895+ this . decorated = decorated ;
896+ const head = document . getElementById ( "head" + this . wid ) ;
883897 if ( decorated ) {
884- jQuery ( `# head${ this . wid } ` ) . show ( ) ;
898+ head . style . display = 'block' ;
885899 jQuery ( this . div ) . removeClass ( "undecorated" ) ;
886900 jQuery ( this . div ) . addClass ( "window" ) ;
887- if ( this . d_header ) {
888- this . topoffset = this . topoffset + Number . parseInt ( jQuery ( this . d_header ) . css ( "height" ) , 10 ) ;
889- this . debug ( "geometry" , "_set_decorated(" , decorated , ") new topoffset=" , self . topoffset ) ;
890- }
891901 } else {
892- jQuery ( `# head${ this . wid } ` ) . hide ( ) ;
902+ head . style . display = 'none' ;
893903 jQuery ( this . div ) . removeClass ( "window" ) ;
894904 jQuery ( this . div ) . addClass ( "undecorated" ) ;
895905 }
906+ this . update_offsets ( ) ;
896907 }
897908
898909 /**
0 commit comments