#!/usr/bin/perl -w
#
# X11 thingy in perl
use strict;
use v5.10;
use X11::Protocol;
use X11::Protocol::WM;
use Package::Alias WM => 'X11::Protocol::WM';
my $X = X11::Protocol->new() or die "Can't seem to find X11...";
say "Found X11, detaching...";
exit if fork;
$X->CreateWindow(
my $window = $X->new_rsrc,
$X->root, # parent window
'InputOutput', # window class
0, # "depth", 0 = copy from parent
0, # "vidual", 0 = copy from parent
0, 0, # window X/Y, window manager will override
97, 32, # width/height
0, # border width
background_pixel => $X->black_pixel,
event_mask => $X->pack_event_mask('Exposure')
);
$X->CreateGC(
my $context = $X->new_rsrc, $window,
foreground => $X->white_pixel
);
$X->{'event_handler'} = sub {
my %event = @_;
'Expose' eq $event{'name'} &&
$X->PolyText8($window, $context, 10, 20, [0, 'Hello, World!']);
'ClientMessage' eq $event{'name'} && do exit;
};
# set title on window
WM::set_wm_name($X, $window, "thingy");
# set title on icon (when minimized, in taskbar, etc)
WM::set_wm_icon_name($X, $window, "thingy");
# requiest to be notified of window closing
WM::set_wm_protocols($X, $window, 'WM_DELETE_WINDOW');
$X->MapWindow($window);
for (;;) { $X->handle_input };