npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

x11-prop

v0.4.3

Published

X11 Properties Coder / Encoder

Downloads

11

Readme

node-x11-prop

Utility to deal with X11 properties

Example

Install x11 and x11-prop module

npm install x11 x11-prop

You can setting, getting properties easily

var x11 = require('x11');
var x11prop = require('x11-prop');
var get_property = x11prop.get_property;
var set_property = x11prop.set_property;

x11.createClient(function(err, display) {
    if (err) {
        throw err;
    }

    var X = display.client;
    var root = display.screen[0].root;
    var wid = X.AllocID();

    /* Create a new window */
    X.CreateWindow(wid, root, 0, 0, 1, 1); // 1x1 pixel window
    X.ChangeWindowAttributes(wid, { eventMask: x11.eventMask.PropertyChange });
    X.on('event', function(ev) {
        /* Get WM_CLASS property */
        get_property(X, wid, ev.atom, 'STRING', function(err, data) {
            if (!err) {
                console.log('WM_CLASS: ' + data);
            }
        });
    });

    /* Set WM_CLASS property. */
    set_property(X, wid, 'WM_CLASS', 'STRING', 8, [ 'My Name', 'My Class' ], true);
});

You can also encode / decode them and then using the x11 core requests directly

var x11 = require('x11');
var x11prop = require('x11-prop');
var decoder = x11prop.decoder;
var encoder = x11prop.encoder;

x11.createClient(function(err, display) {
    if (err) {
        throw err;
    }

    var X = display.client;
    var root = display.screen[0].root;
    var wid = X.AllocID();

    /* Create a new window */
    X.CreateWindow(wid, root, 0, 0, 1, 1); // 1x1 pixel window
    X.ChangeWindowAttributes(wid, { eventMask: x11.eventMask.PropertyChange });
    X.on('event', function(ev) {
        /* Get property and decode the data */
        X.GetProperty(0, wid, X.atoms.WM_CLASS, X.atoms.STRING, 0, 1000000000, function(err, prop) {
            if (!err) {
                var decoded_data = decoder.decode('STRING', prop.data);
                console.log('Decoded WM_CLASS: ' + decoded_data);
            }
        });
    });

    /*
     * Set WM_CLASS property. Use the encoder to generate the data
     * We set the third parameter to true because WM_CLASS strings are null terminated.
     */
    var data = encoder.encode('STRING', [ 'My Name', 'My Class' ], true);
    X.ChangeProperty(0, wid, X.atoms.WM_CLASS, X.atoms.STRING, 8, data);
});

Supported Types

STRING, UTF8_STRING, ATOM, INTEGER, CARDINAL, WINDOW, WM_STATE, _XSETTINGS_SETTINGS

API

Set property

x11prop.set_property(X, wid, prop, type, format, data[, null_terminated], cb)

X : X client from x11 library
wid : window id
prop : property (string or atom)
type : type of the property (string or atom)
format : 8, 16, 32
data : 1 - Array of strings for string properties: STRING, UTF8_STRING
       2 - Array of integers for ATOM, INTEGER, CARDINAL, WINDOW
       3 - For WM_STATE: { state : integer [, icon : integer ]}
       4 - For _XSETTINGS_SETTINGS: { serial: integer, setting1 : { type:
                                      integer, serial: integer, value: {}}, ... }
           See: https://github.com/sidorares/x11-xsettings
null_terminated : (optional AND only for string properties) if true, the strings will be null terminated.
                  Otherwise, they will be null separated.

Get property

x11prop.get_property(X, wid, prop, type, cb)

X : X client from x11 library
wid : window id
prop : property (string or atom)
type : type of the property (string or atom)
cb : function(err, result), where result is the decoded property value

Encode

x11prop.encode(type, data [, null_terminated ])

type : string with one of the supported types
data : 1 - Array of strings for string properties: STRING, UTF8_STRING
       2 - Array of integers for ATOM, INTEGER, CARDINAL, WINDOW
       3 - For WM_STATE: { state : integer [, icon : integer ]}
       4 - For _XSETTINGS_SETTINGS: { serial: integer, setting1 : { type:
                                      integer, serial: integer, value: {}}, ... }
           See: https://github.com/sidorares/x11-xsettings
null_terminated : (optional AND only for string properties) if true, the strings will be null terminated.
                  Otherwise, they will be null separated

Decode

x11prop.decode(type, data)

type : string with one of the supported types
data : data field of the property object returned by *X.GetProperty*