Skip to content

Commit da79468

Browse files
committed
add support for linux again
1 parent e4a91f5 commit da79468

File tree

4 files changed

+75
-36
lines changed

4 files changed

+75
-36
lines changed

extensions/xglass/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
All important modifications to this VSCode theme collection will be documented in this file.
44

55
---
6+
## [1.0.2]
7+
- update linux support
8+
69
## [1.0.1]
710
- Fixed package json, activation events was deleted following the standard
811
- Added activation event onCommand:xglass.enable.

extensions/xglass/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ xprop -id <windowId> -f _NET_WM_WINDOW_OPACITY 32c \
118118
* **Scope:** Only adjusts **window attributes** (opacity) of the current VS Code process.
119119
* **Windows:** Loads a small **in-memory C# helper** via PowerShell (`Add-Type`). No additional files are written.
120120
* **Linux:** Uses `xprop` (X11 only). **Wayland not supported**.
121-
121+
* **This extension deos not acces, modify, or interact with any process or window outside of the current VS Code instance.**
122122
---
123123

124124
## Compatibility & Limitations
@@ -155,7 +155,7 @@ xprop -id <windowId> -f _NET_WM_WINDOW_OPACITY 32c \
155155
* From VSIX:
156156

157157
```bash
158-
code --install-extension xglass-1.0.1.vsix
158+
code --install-extension xglass-1.0.2.vsix
159159
```
160160
* Or search **“XGlass”** in the Extensions view and install.
161161

extensions/xglass/extension.js

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/0x[\da-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-zA-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(/0x[\da-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

extensions/xglass/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "xglass",
33
"displayName": "Xglass",
44
"description": "Make of glass your editor",
5-
"version": "1.0.1",
5+
"version": "1.0.2",
66
"publisher": "xscriptor",
77
"license": "MIT",
88
"engines": {

0 commit comments

Comments
 (0)