GithubHelp home page GithubHelp logo

clj-xscreensaver-basic-demo's Introduction

clj-xscreensaver-basic-demo

This is a very basic proof-of-concept demo of an XScreenSaver hack implemented in Clojure. It relies on JNA to to write to the hack window.

Running it

Build with lein uberjar or download clj-xscreensaver-basic-demo-0.0.1-standalone.jar.

Stop XScreenSaver with xscreensaver-command -exit.

Edit your ~/.xscreensaver config file and add this to the list of hacks, adjusting the path as necessary:

                        "arcs"  java -jar ./clj-xscreensaver-basic-demo-0.0.1-standalone.jar \n\

Start XScreenSaver with xscreensaver &. You’ll now find a hack named "arcs" in the list when you start xscreensaver-demo.

How it works

XScreenSaver hacks work by drawing on a window created by the main daemon. The window id is passed both as the XSCREENSAVER_WINDOW environment variable and on command line to the hack.

AWT does not support using remote window IDs in any way (I’ve tried). But JNA supports X11, which provides enough of the necessary X11 functions to get around that limiation.

Roughly, this demo follows these steps:

  • Connect to the $DISPLAY

  • Create a new Window with the window id of a foreign window

  • Get the XWindowAttributes of the window

  • Create an XGCValues to get the graphics context of that window

  • Create a Java BufferedImage and draw on it

  • Create a JNA Memory "buffer"

  • Create an XImage pointing to that buffer

Then in a loop:

  • Draw on the BufferedImage using standard Java2D or AWT methods

  • Copy the BufferedImage data to the Memory buffer

  • Write the image (from the buffer) to the window with XPutImage

X related resources are freed in a shutdown hook.

Bugs and Questions

I’m not sure I’ve handled the bit depth correctly. This might be using more memory than necessary.

Only 32 and 24 bit depths are currently handled.

clj-xscreensaver-basic-demo's People

Contributors

robbieh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.