From 9e967b9734d65d7e24753ae2a285c454d8e96ff3 Mon Sep 17 00:00:00 2001 From: Svetlana Linuxenko Date: Fri, 18 Nov 2016 14:50:10 +0200 Subject: [PATCH] GCFunction shortcuts --- examples/simple/gcinvert.js | 36 ++++++++++++++++++++++++++++++++++++ lib/gcfunction.js | 22 ++++++++++++++++++++++ lib/index.js | 5 +++++ 3 files changed, 63 insertions(+) create mode 100644 examples/simple/gcinvert.js create mode 100644 lib/gcfunction.js diff --git a/examples/simple/gcinvert.js b/examples/simple/gcinvert.js new file mode 100644 index 0000000..b9d5a82 --- /dev/null +++ b/examples/simple/gcinvert.js @@ -0,0 +1,36 @@ +/* + * GCFunction usage example + */ +var x11 = require('../../lib'); + +x11.createClient(function(err, display) { + var X = display.client; + var root = display.screen[0].root; + var white = display.screen[0].white_pixel; + var black = display.screen[0].black_pixel; + + var wid = X.AllocID(); + X.CreateWindow(wid, root, 0, 0, 400, 300, 0, 0, 0, 0, { + backgroundPixel: black, + eventMask: x11.eventMask.ButtonPress|x11.eventMask.Exposure }); + var gc = X.AllocID(); + X.CreateGC(gc, wid, {foreground : white, 'function' : x11.gcFunction.GXinvert}); + X.MapWindow(wid); + + + X.on('event', function(ev) { + + if (ev.type === 12) { + X.PolyFillRectangle(wid, gc, [0, 0, 400, 300]); + } + + if (ev.type === 4) { + var x = ev.x; + var y = ev.y; + + X.PolyFillRectangle(wid, gc, [x - 25, y - 25, 50, 50]); + } + + }); +}); + diff --git a/lib/gcfunction.js b/lib/gcfunction.js new file mode 100644 index 0000000..d57f10c --- /dev/null +++ b/lib/gcfunction.js @@ -0,0 +1,22 @@ +/* + * GCFunction named shortcuts + */ + +module.exports = { + GXclear : 0x0, + GXand : 0x1, + GXandReverse : 0x2, + GXcopy : 0x3, + GXandInverted : 0x4, + GXnoop : 0x5, + GXxor : 0x6, + GXor : 0x7, + GXnor : 0x8, + GXequiv : 0x9, + GXinvert : 0xa, + GXorReverse : 0xb, + GXcopyInverted : 0xc, + GXorInverted : 0xd, + GXnand : 0xe, + GXset : 0xf +}; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index b5b4af2..cab9d37 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,6 +11,11 @@ Object.defineProperty(module.exports, 'keySyms', { get: function() { return require('./keysyms'); } }); +Object.defineProperty(module.exports, 'gcFunction', { + enumerable: true, + get: function() { return require('./gcfunction'); } +}); + //TODO: // keepe everything in namespace for consistensy (eventMask, keySyms, class, destination ... // or put most used constants to top namespace? (currently class and destination in top)