Skip to content

Instantly share code, notes, and snippets.

@yorickvP
Last active September 20, 2016 09:56
Show Gist options
  • Save yorickvP/6cca7e8a736f5ff28f9bc077ce61d129 to your computer and use it in GitHub Desktop.
Save yorickvP/6cca7e8a736f5ff28f9bc077ce61d129 to your computer and use it in GitHub Desktop.
electron-desktop
node_modules
#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
#include <X11/Xlib.h>
int XMapWindow(Display *display, Window w) {
static int (*old_map)(Display *, Window) = (int (*)(Display *, Window))dlsym(RTLD_NEXT, "XMapWindow");
static Atom net_wm_window_type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", True);
static Atom ATOM = XInternAtom(display, "ATOM", True);
Atom actual_type_return;
int actual_format_return;
unsigned long nitems_return, bytes_after_return;
Atom * prop_return;
if (XGetWindowProperty(display, w, net_wm_window_type, 0, 1, False, ATOM,
&actual_type_return, &actual_format_return, &nitems_return, &bytes_after_return,
(unsigned char**)&prop_return) == Success) {
if (nitems_return > 0) {
if (prop_return[0] == XInternAtom(display, "_NET_WM_WINDOW_TYPE_DESKTOP", False)) {
XSetWindowAttributes xattr;
xattr.override_redirect = True;
XChangeWindowAttributes(display, w, CWOverrideRedirect, &xattr);
printf("setting override redirect on %d\n", w);
XLowerWindow(display, w);
}
}
XFree(prop_return);
}
return old_map(display, w);
}
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<style>html, body {
margin: 0; padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<!--<h1>Hello World!</h1>
We are using node <script>document.write(process.versions.node)</script>,
Chrome <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.-->
<webview id="foo" src="http://localhost:8089/" style="width:100%; height:100%"></webview>
</body>
</html>

Copyright (c) 2015 GitHub Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

var app = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.
var x11 = require('x11');
var x11_prop = require('x11-prop');
// Report crashes to our server.
//require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
var screen = require('screen');
var size = screen.getPrimaryDisplay().workAreaSize;
console.log(screen.getAllDisplays());
// Create the browser window.
mainWindow = new BrowserWindow({
width: size.width, height: size.height - 20, type: 'desktop', frame: false, x: 0, y: 20,
resizable: false
});
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', function() {
mainWindow = null;
});
mainWindow.setVisibleOnAllWorkspaces(true);
console.log(mainWindow.id, process.pid);
setTimeout(scan_windows, 100);
});
function for_all_windows(X, root, fn) {
X.QueryTree(root, function(err, tree) {
tree.children.forEach(function(wid) {
fn(wid);
for_all_windows(X, wid, fn);
});
});
}
function scan_windows() {
x11.createClient(function(err, display) {
X = display.client;
root = display.screen[0].root;
X.InternAtom(false, "_NET_WM_WINDOW_TYPE_DESKTOP", function(err, _NET_WM_WINDOW_TYPE_DESKTOP) {
for_all_windows(X, root, function(wid) {
x11_prop.get_property(X, wid, "_NET_WM_PID", 'CARDINAL', function(err, data) {
if (data == process.pid) {
x11_prop.get_property(X, wid, "_NET_WM_WINDOW_TYPE", 'ATOM', function(err, data) {
if (!err) {
if (data.some(function(x) { return x == _NET_WM_WINDOW_TYPE_DESKTOP; })) {
console.log("FOUND", wid)
set_state(X, wid);
}
console.log(wid, '_NET_WM_WINDOW_TYPE: ' + data);
}
});
if (!err) {
console.log(wid, '_NET_WM_PID: ' + data);
}
}
});
});
});
});
}
function set_state(X, wid) {
X.LowerWindow(wid);
}
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron main.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/atom/electron-quick-start.git"
},
"keywords": [
"Electron",
"quick",
"start",
"tutorial"
],
"author": "GitHub",
"license": "MIT",
"bugs": {
"url": "https://github.com/atom/electron-quick-start/issues"
},
"homepage": "https://github.com/atom/electron-quick-start#readme",
"devDependencies": {
"electron-prebuilt": "^0.34.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment