@@ -44,48 +44,84 @@ function activate(context) {
4444 }
4545 } ;
4646 } else if ( process . platform === 'linux' ) {
47- const cp = require ( 'child_process' ) ;
47+ const cp = require ( 'child_process' ) ;
4848
49- let codeWindowIds = [ ] ;
50- try {
51- cp . spawnSync ( 'which' , [ 'xprop' ] , { stdio : 'ignore' } ) ;
49+ // Verifica xprop (X11). Si no está, deja un setAlpha que solo avisa.
50+ try {
51+ cp . spawnSync ( 'which' , [ 'xprop' ] , { stdio : 'ignore' } ) ;
52+ } catch {
53+ setAlpha = ( ) => window . showErrorMessage ( 'xglass Error: xprop not found (X11 only).' ) ;
54+ }
5255
53- const processIds = cp . execSync ( `pgrep 'code'` ) . toString ( ) . trim ( ) . split ( '\n' ) . filter ( Boolean ) ;
54- const allWindowIdsOutput = cp . execSync ( `xprop -root | grep '_NET_CLIENT_LIST(WINDOW)'` ) . toString ( ) ;
55- const allWindowIds = ( allWindowIdsOutput . match ( / 0 x [ \d a - f ] + / ig) || [ ] ) ;
56+ // Opcional: aviso si estás en Wayland
57+ if ( process . env . XDG_SESSION_TYPE === 'wayland' ) {
58+ console . warn ( 'xglass: Wayland session detected — not supported.' ) ;
59+ }
5660
57- for ( const windowId of allWindowIds ) {
58- const hasProcessId = cp . execSync ( `xprop -id ${ windowId } _NET_WM_PID` ) . toString ( ) ;
59- if ( ! ( hasProcessId . search ( 'not found' ) + 1 ) ) {
60- const winProcessId = hasProcessId . replace ( / ( [ a - z A - Z _ ( ) \\ s = ] ) / g, '' ) ;
61- if ( processIds . includes ( winProcessId ) ) codeWindowIds . push ( windowId ) ;
61+ // Obtiene SIEMPRE las ventanas actuales de VS Code (code o code-insiders)
62+ const getCodeWindowIds = ( ) => {
63+ try {
64+ let pids = [ ] ;
65+ try {
66+ pids = cp . execSync ( `pgrep -f 'code(-insiders)?$'` ) . toString ( ) . trim ( ) . split ( '\n' ) . filter ( Boolean ) ;
67+ } catch {
68+ try {
69+ pids = cp . execSync ( `pgrep 'code'` ) . toString ( ) . trim ( ) . split ( '\n' ) . filter ( Boolean ) ;
70+ } catch {
71+ pids = [ ] ;
6272 }
6373 }
74+ if ( ! pids . length ) return [ ] ;
6475
65- setAlpha = ( alpha ) => {
66- if ( alpha < 1 ) alpha = 1 ;
67- else if ( alpha > 255 ) alpha = 255 ;
76+ const root = cp . execSync ( `xprop -root | grep '_NET_CLIENT_LIST(WINDOW)'` ) . toString ( ) ;
77+ const allIds = ( root . match ( / 0 x [ \d a - f ] + / ig ) || [ ] ) ;
78+ const codeIds = [ ] ;
6879
69- for ( const id of codeWindowIds ) {
70- cp . exec (
71- `xprop -id ${ id } -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * ${ alpha } / 255)))` ,
72- async ( error ) => {
73- if ( error ) {
74- console . error ( error ) ;
75- window . showErrorMessage ( `xglass Error (linux): ${ error . message } ` ) ;
76- return ;
77- }
78- console . log ( `xglass: set alpha ${ alpha } ` ) ;
79- await config ( ) . update ( 'alpha' , alpha , true ) ;
80- }
81- ) ;
82- }
83- } ;
80+ for ( const wid of allIds ) {
81+ const pidLine = cp . execSync ( `xprop -id ${ wid } _NET_WM_PID` ) . toString ( ) ;
82+ const m = pidLine . match ( / \d + / ) ;
83+ const winPid = m ? m [ 0 ] : null ;
84+ if ( winPid && pids . includes ( winPid ) ) codeIds . push ( wid ) ;
85+ }
86+ return codeIds ;
8487 } catch ( e ) {
85- console . error ( e ) ;
86- setAlpha = ( ) => window . showErrorMessage ( 'xglass Error: xprop / windows not available.' ) ;
88+ console . error ( 'xglass(linux): getCodeWindowIds failed' , e ) ;
89+ return [ ] ;
8790 }
88- }
91+ } ;
92+
93+ setAlpha = ( alpha ) => {
94+ try {
95+ if ( alpha < 1 ) alpha = 1 ;
96+ else if ( alpha > 255 ) alpha = 255 ;
97+
98+ const ids = getCodeWindowIds ( ) ;
99+ if ( ! ids . length ) {
100+ window . showWarningMessage ( 'xglass: no VS Code windows found (X11). Are you on Wayland?' ) ;
101+ return ;
102+ }
103+
104+ for ( const id of ids ) {
105+ cp . exec (
106+ `xprop -id ${ id } -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * ${ alpha } / 255)))` ,
107+ async ( error ) => {
108+ if ( error ) {
109+ console . error ( 'xglass(linux): xprop error' , error ) ;
110+ window . showErrorMessage ( `xglass Error (linux): ${ error . message } ` ) ;
111+ return ;
112+ }
113+ console . log ( `xglass(linux): set alpha ${ alpha } ` ) ;
114+ await config ( ) . update ( 'alpha' , alpha , true ) ;
115+ }
116+ ) ;
117+ }
118+ } catch ( err ) {
119+ console . error ( err ) ;
120+ window . showErrorMessage ( `xglass Error (linux): ${ err . message || err } ` ) ;
121+ }
122+ } ;
123+ }
124+
89125
90126 console . log ( 'xglass VSC active' ) ;
91127
0 commit comments