Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

x window programming in perl

by cspctec (Sexton)
on Jun 19, 2014 at 14:57 UTC ( [id://1090478]=perlquestion: print w/replies, xml ) Need Help??

cspctec has asked for the wisdom of the Perl Monks concerning the following question:

I have created a C program that raises a window to the front of the window stack on Solaris, and I'm really wanting to change it to be perl only. I use the "XRaiseWindow" and "XSetInputFocus" function from the X11 library in my C program. I've been reading about the perl X11::Protocol module lately, but I don't see any of the C functions I used to raise a window (like XRaiseWindow).

Are the C functions from the X11 library available to perl scripts? It would be awesome to have a simple perl script that raised a window instead of having to bother with compiling a C program.

Replies are listed 'Best First'.
Re: x window programming in perl
by roboticus (Chancellor) on Jun 19, 2014 at 15:49 UTC

    cspctec:

    At first, I was going to suggest that you add the RaiseWindow function to X11::Protocol, but it turns out that the function doesn't exist. (The stuff below the line shows what I was going to suggest.

    It seems that to raise a window to the top of the stack, you call the ConfigureRequest function, giving it the stack mode "Above" to bring it to the top. Since ConfigureRequest is in the X11::Protocol package, you should be able to call that to take care of it.


    I did a brief review of the X11::Protocol code, and it looks like it wouldn't be too difficult to add XRaiseWindow. The code appears to simply format binary packets according to the X11 protocol, and it seems to do so in a straightforward manner. So it may be an easy matter to simply add the function(s) you want. If you do so, be sure to submit a patch to the author for inclusion.

    For example, here's the bit of code that packs up the "CreateWindow" message:

    ['CreateWindow', sub { my $self = shift; my($wid, $parent, $class, $depth, $visual, $x, $y, $width, $height, $border_width, %values) = @_; my($mask, $i, @values); $mask = 0; for $i (0 .. 14) { if (exists $values{$Attributes_ValueMask[$i][0]}) { $mask |= (1 << $i); push @values, &{$Attributes_ValueMask[$i][1]} ($self, $values{$Attributes_ValueMask[$i][0]}); } } $visual = 0 if $visual eq 'CopyFromParent'; $class = $self->num('Class', $class); return pack("LLssSSSSLL", $wid, $parent, $x, $y, $width, $height, $border_width, $class, $visual, $mask) . join("", @values), $depth; }],

    Notice how similar the parameter list is to the X11 specification:

    CreateWindow

    wid, parent: WINDOW class: { InputOutput, InputOnly, CopyFromParent} depth: CARD8 visual: VISUALID or CopyFromParent x, y: INT16 width, height, border-width: CARD16 value-mask: BITMASK value-list: LISTofVALUE Errors: Alloc, Colormap, Cursor, IDChoice, Match, Pixmap, Value, Window

    So all we need to do is find the interface for the raise window function, and create a similar packing routine to do the job.

    Hmmm ... let me see ... RaiseWindow ... doesn't seem to exist....

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: x window programming in perl
by zentara (Archbishop) on Jun 19, 2014 at 17:32 UTC
    Are the C functions from the X11 library available to perl scripts? It would be awesome to have a simple perl script that raised a window instead of having to bother with compiling a C program.

    Are you averse to using Tk or Prima? Tk compiles well on most systems with few difficulties, and requires no extra base libraries. It makes opening a window a breeze.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: x window programming in perl
by marto (Cardinal) on Jun 19, 2014 at 15:44 UTC
Re: x window programming in perl
by cspctec (Sexton) on Jun 19, 2014 at 16:03 UTC
    Thanks guys, I'll probably just try both of those modules and see how it goes. It will take me a while to get the modules on these systems, unfortunately. I'll try to post back and let you guys know if it works out.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1090478]
Approved by Perlbotics
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found