[KWin Scripting] KWin|Pong: play your window
EDIT: Sorry for the downtime, but the website is back up again
I apologize for the video looking very choppy.. but I couldn’t really help it. After I ran recordmydesktop, it just sucked my CPU into a blinding vortex. And that was after I used a polling interval of 160ms. Either ways, I have also added a video taken from my phone’s camera at the end of this video to show that the performance is actually not all that bad.
Till now whenever I had to test something done with KWin scripting, I just used to add a few little lines to the defaultscript that runs and then just check it out. As such, I was testing everything one thing at a time. I just wanted to write a bigger script, something that used a set of these implemented things to do something.. and what better symbol of nerdism than pong? So, I went ahead and wrote a pong game.. all done in QtScript. The video is for all to see, and a few things to note are:
1. The pong game is written entirely using scripting.
2. I did not and absolutely did not add anything from the C++ side to facilitate anything.
3. The performance was actually close enough to what I would get from native code, even at a polling interval of as low as 30ms.
4. The QTimer class used in this game are linked from plasma, marking the first step in linking of plasma script bindings into KWin scripting. Although it may look a pretty natural thing, it somehow happens to be a big deal to me
KWin|Pong from Rohan Prabhu on Vimeo.
What is going on:
1. When loaded, the pong game does all the output to the console.
2. It asks the player to select the various controls in the game. In the game I’ve selected a Firefox browser as my paddle, and a Chrome window as my other paddle. A quite unique scenario of browser wars. And a nice little xterm window plays the ball and a konsole window shows me the score.
3. To ‘select’ a window for a purpose, I just have to bring on the focus to the window.
4. I move the firefox window with my mouse and it is my paddle. The movements are restricted to this window, meaning I can move it only along the y-axis. It always stays snapped to the left edge of the screen.
5. The chrome window uses a very stupid and rudimentary AI which was born to lose.
6. Whenever a player scores, the konsole window shows up the score and the party which scored.
Technically,
1. The selection of different windows is done using the workspace.clientActivated event, which is evoked whenever a client receives focus.
2. The resizing, moving is done using a variety of available geometry functions for client objects.
3. The player paddle is constrained using the client.moved event.
Hope you like it! Again, sorry for the choppy video. The script of the game is available here [kwinpong.txt], or if you prefer syntax highlighted, here [kwinpong.txt (hl)]. Video editing was done in kdenlive and the audio editing was done in Audacity
And a screenshot to wrap it up:

The idea of playing pong with windows is so utterly crazy and horribly wrong, that I’m all the more enthused that someone actually implemented it.
Thanks for the great scripting demo!
Rohan,
Nice to see your site back up again and even more awesome to see you scripting on KWin. Ill be sure to visit your website more often – considering that you are developing on linux
Great! I can switch to Linux now full time!