Skip to content

Instantly share code, notes, and snippets.

View javiercantero's full-sized avatar

Javier Cantero javiercantero

View GitHub Profile
@javiercantero
javiercantero / CPRreader.py
Created May 10, 2017 14:06
Tool to unpack Ascalon games (such as Patrician III) .CPR files
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#
# CPRreader - reads and unpacks .CPR files from Patrician Ascalon games
#
# Copyright (C) 2014, 2017 Javier Cantero
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@javiercantero
javiercantero / inline2ldr
Created March 3, 2016 11:28
A simple script to transform Wikipedia articles from inline references style to list-defined references style
#!/usr/bin/python3
#
# inline2ldr
#
# Extract all the inline citations from a Wikipedia article's text and
# paste them into the {{reflist}} template. The tool automatically
# generates name references ("autoref0001", ...) for those without one.
#
# Usage: inline2ldr < article-orig.txt > article.txt
#
@javiercantero
javiercantero / keyb-eavesdrop.c
Created July 10, 2014 17:16
Little app to lock the keyboard input of a libOIS linked application (this include games like FreeOrion but also the OISConsole demo packed with the library). You can restore the keyboard input simply by terminate the app killing it or sending a ESC key. This program simulates the functionality of xscreensaver to eaversdrop theKeyPress events of…
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
/* taken from xscreensaver's timers.c */
/* ---------------------------------------------------------------------------
* this function tries to eavesdrop all the keyboard activity of any window of
* the X server (to determine if a user is active or not and launch the
* screensaver if needed). The comment inside is from xscreensaver author. See
@javiercantero
javiercantero / xreadkeys.c
Last active June 24, 2024 16:45
A X11/Xlib program that reads the KeyPress and KeyRelease events from the window and prints them to the standard output. Used to debug the keyboard within X.
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
Display *display;
Window window;
XEvent event;
int s;
@javiercantero
javiercantero / xtrace_patchedFO_openbox.log
Created December 2, 2013 17:41
Tracing X input events to try to debug keyboard problems with FreeOrion (with k1ll_key_autorepeat_fix patch applied to libOIS), from within OpenBox (no DE, pure X). The sequence of pulsations for the first input text box was "abcdefghijklmnopqrstuvwxyz", and for the second "1234567890". The first input text box shows the entire "abcdefghijklmnop…
... (more stuff) ...
004:>:0015: Event ButtonPress(4) button=left button(0x01) time=0x00e3ea53 root=0x0000028e event=0x01800002 child=None(0x00000000) root-x=148 root-y=658 event-x=147 event-y=640 state=0 same-screen=true(0x01)
004:>:0015: Event ButtonRelease(5) button=left button(0x01) time=0x00e3eaab root=0x0000028e event=0x01800002 child=None(0x00000000) root-x=148 root-y=658 event-x=147 event-y=640 state=Button1 same-screen=true(0x01)
003:>:0007: Event KeyPress(2) keycode=0x26 time=0x00e3f1ac root=0x0000028e event=0x01800002 child=None(0x00000000) root-x=1018 root-y=368 event-x=1017 event-y=350 state=0 same-screen=true(0x01)
003:<:0008: 28: XKEYBOARD-Request(135,8): GetMap opcode=0x87 opcode2=0x08 unparsed_data=...;
003:>:0008:5068: Reply to GetMap: data1=0x01 data2=0x03 unparsed_data=...;
003:<:0009: 20: XKEYBOARD-Request(135,1): SelectEvents opcode=0x87 opcode2=0x01 unparsed_data=...;
003:<:000a: 16: XKEYBOARD-Request(135,1): SelectEvents opcode=0x87 opcode2=0x01 unparsed_data=...;
003:>:000a: Event Key
@javiercantero
javiercantero / xtrace_FO_openbox.log
Created December 2, 2013 17:39
Tracing X input events to try to debug keyboard problems with FreeOrion, from within OpenBox (no DE, pure X). The sequence of pulsations for the first input text box was "abcdefghijklmnopqrstuvwxyz", and for the second "1234567890". The first input text box shows the entire "abcdefghijklmnopqrstuvwxyz" sequence and the second also shows the enti…
... (more stuff) ...
004:>:0015: Event ButtonPress(4) button=left button(0x01) time=0x00e68faa root=0x0000028e event=0x01800002 child=None(0x00000000) root-x=179 root-y=653 event-x=178 event-y=635 state=0 same-screen=true(0x01)
004:>:0015: Event ButtonRelease(5) button=left button(0x01) time=0x00e69022 root=0x0000028e event=0x01800002 child=None(0x00000000) root-x=179 root-y=653 event-x=178 event-y=635 state=Button1 same-screen=true(0x01)
003:>:0007: Event KeyPress(2) keycode=0x26 time=0x00e69625 root=0x0000028e event=0x01800002 child=None(0x00000000) root-x=716 root-y=465 event-x=715 event-y=447 state=0 same-screen=true(0x01)
003:<:0008: 28: XKEYBOARD-Request(135,8): GetMap opcode=0x87 opcode2=0x08 unparsed_data=...;
003:>:0008:5068: Reply to GetMap: data1=0x01 data2=0x03 unparsed_data=...;
003:<:0009: 20: XKEYBOARD-Request(135,1): SelectEvents opcode=0x87 opcode2=0x01 unparsed_data=...;
003:<:000a: 16: XKEYBOARD-Request(135,1): SelectEvents opcode=0x87 opcode2=0x01 unparsed_data=...;
003:>:000a: Event KeyRe
@javiercantero
javiercantero / xtrace_patchedFO.log
Created December 2, 2013 17:07
Tracing X input events to try to debug keyboard problems with FreeOrion (with k1ll_key_autorepeat_fix patch applied to libOIS), from within Xfce 4.10. The sequence of pulsations for the first input text box was "abcdefghijklmnopqrstuvwxyz", and for the second "1234567890". The first input text box shows the entire "abcdefghijklmnopqrstuvwxyz" se…
... (more stuff) ...
004:>:0015: Event ButtonPress(4) button=left button(0x01) time=0x00cc8add root=0x0000028e event=0x03e00002 child=None(0x00000000) root-x=172 root-y=693 event-x=171 event-y=640 state=0 same-screen=true(0x01)
004:>:0015: Event ButtonRelease(5) button=left button(0x01) time=0x00cc8b35 root=0x0000028e event=0x03e00002 child=None(0x00000000) root-x=172 root-y=693 event-x=171 event-y=640 state=Button1 same-screen=true(0x01)
003:>:0007: Event KeyPress(2) keycode=0x26 time=0x00cc9227 root=0x0000028e event=0x03e00002 child=None(0x00000000) root-x=875 root-y=556 event-x=874 event-y=503 state=0 same-screen=true(0x01)
003:<:0008: 28: XKEYBOARD-Request(135,8): GetMap opcode=0x87 opcode2=0x08 unparsed_data=...;
003:>:0008:5068: Reply to GetMap: data1=0x01 data2=0x03 unparsed_data=...;
003:<:0009: 20: XKEYBOARD-Request(135,1): SelectEvents opcode=0x87 opcode2=0x01 unparsed_data=...;
003:<:000a: 16: XKEYBOARD-Request(135,1): SelectEvents opcode=0x87 opcode2=0x01 unparsed_data=...;
003:>:000a: Event KeyRe
@javiercantero
javiercantero / xtrace_FO.log
Last active December 30, 2015 00:49
Tracing X input events to try to debug keyboard problems with FreeOrion, from within Xfce 4.10. The sequence of pulsations for the first input text box was "abcdefghijklmnopqrstuvwxyz", and for the second "1234567890". The first input text box only shows "abcdefghijklmnopq". The second input text box shows nothing.
... (more stuff) ...
004:>:0015: Event ButtonPress(4) button=right button(0x03) time=0x00b96f36 root=0x0000028e event=0x03e00002 child=None(0x00000000) root-x=165 root-y=686 event-x=164 event-y=633 state=0 same-screen=true(0x01)
004:>:0015: Event ButtonRelease(5) button=right button(0x03) time=0x00b96fde root=0x0000028e event=0x03e00002 child=None(0x00000000) root-x=165 root-y=686 event-x=164 event-y=633 state=Button3 same-screen=true(0x01)
004:>:0015: Event ButtonPress(4) button=left button(0x01) time=0x00b97376 root=0x0000028e event=0x03e00002 child=None(0x00000000) root-x=206 root-y=690 event-x=205 event-y=637 state=0 same-screen=true(0x01)
004:>:0015: Event ButtonRelease(5) button=left button(0x01) time=0x00b97406 root=0x0000028e event=0x03e00002 child=None(0x00000000) root-x=206 root-y=690 event-x=205 event-y=637 state=Button1 same-screen=true(0x01)
003:>:0007: Event KeyPress(2) keycode=0x26 time=0x00b97f3e root=0x0000028e event=0x03e00002 child=None(0x00000000) root-x=980 root-y=568 event-x=979 event-y=
@javiercantero
javiercantero / k1ll-x11_key_repeat_fix.diff
Created November 24, 2013 16:44
The exact patch I applied to the FreeOrion 0.4.3 version of libOIS to get the keyboard working on Linux (see http://www.freeorion.org/forum/viewtopic.php?f=25&t=7719 for more info).
diff -rub ois-master/includes/linux/LinuxKeyboard.h ois-k1ll-x11_key_repeat_fix/includes/linux/LinuxKeyboard.h
--- ois-master/includes/linux/LinuxKeyboard.h 2013-11-22 18:36:58.131433711 +0100
+++ ois-k1ll-x11_key_repeat_fix/includes/linux/LinuxKeyboard.h 2013-11-22 18:48:08.343445383 +0100
@@ -68,7 +68,6 @@
XPeekEvent(display, &e);
if(e.type == KeyPress && e.xkey.keycode == event.xkey.keycode && (e.xkey.time - event.xkey.time) < 2)
{
- XNextEvent(display, &e);
return true;
}
@javiercantero
javiercantero / libois-1.3.0-freeorion-patches.diff
Created November 24, 2013 16:18
These are the differences between the 1.3.0 source tree from http://packages.debian.org/source/jessie/ois and https://github.com/freeorion/freeorion/tree/master/FreeOrion/OIS (the non-linux stuff is deleted from debian sources, so this diff only applies to linux differences). Note the use of -b to avoid including blank diffs, but still some chan…
diff -rub --strip-trailing-cr ois-v1-3/src/linux/LinuxInputManager.cpp ois-freeorion-0.4.3/src/linux/LinuxInputManager.cpp
--- ois-v1-3/src/linux/LinuxInputManager.cpp 2010-08-16 00:51:34.000000000 +0200
+++ ois-freeorion-0.4.3/src/linux/LinuxInputManager.cpp 2013-11-21 16:09:53.000000000 +0100
@@ -26,6 +26,7 @@
#include "linux/LinuxMouse.h"
#include "OISException.h"
#include <cstdlib>
+#include <stdio.h>
using namespace OIS;