Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for the simpler functions in Xresources.h #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lib/X11/Xlib/XEvent.pm
lib/X11/Xlib/XID.pm
lib/X11/Xlib/XRectangle.pm
lib/X11/Xlib/XRenderPictFormat.pm
lib/X11/Xlib/XrmDatabase.pm
lib/X11/Xlib/XSetWindowAttributes.pm
lib/X11/Xlib/XSizeHints.pm
lib/X11/Xlib/XVisualInfo.pm
Expand All @@ -45,5 +46,7 @@ t/37-input-kb.t
t/40-screen-attrs.t
t/42-window.t
t/43-pixmap.t
t/50-resources.t
t/70-xcomposite.t
t/xresources
t/lib/X11/SandboxServer.pm
3 changes: 2 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ BEGIN {
'ExtUtils::MakeMaker' => 0,
);
%TEST_REQUIRES= (
'Test::More' => 0,
'Test::More' => 1.001014,
'Test::TempDir::Tiny' => 0,
);
%PREREQ_PM= (
'Try::Tiny' => 0,
Expand Down
112 changes: 112 additions & 0 deletions Xlib.xs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xlibint.h>
#include <X11/Xresource.h>
#include <X11/extensions/XTest.h>
#ifdef HAVE_XCOMPOSITE
#include <X11/extensions/Xcomposite.h>
Expand All @@ -23,6 +24,8 @@
#include "PerlXlib.h"
void PerlXlib_sanity_check_data_structures();

typedef XrmDatabase XrmDatabaseMaybe;

MODULE = X11::Xlib PACKAGE = X11::Xlib

void
Expand Down Expand Up @@ -1619,6 +1622,115 @@ _install_error_handlers(nonfatal,fatal)
CODE:
PerlXlib_install_error_handlers(nonfatal, fatal);

# Xresources Functions (fn_resources) -------------------------------------------------------

void
XrmInitialize()

XrmDatabase
XrmGetFileDatabase( filename )
char *filename

void
XrmPutFileDatabase( database, stored_db )
XrmDatabase database
char *stored_db

char *
XResourceManagerString(display)
Display *display

char *
XScreenResourceString(screen)
Screen *screen

XrmDatabase
XrmGetStringDatabase(data)
char *data

const char *
XrmLocaleOfDatabase(database)
XrmDatabase database

void
XrmDestroyDatabase(IN_OUT XrmDatabase database)
CODE:
XrmDestroyDatabase( database );
database = NULL;

void
XrmSetDatabase( display, database)
Display *display
XrmDatabase database

XrmDatabase
XrmGetDatabase( display )
Display *display

Status
XrmCombineFileDatabase(filename, IN_OUT XrmDatabaseMaybe target_db, override )
char* filename
Bool override

void
XrmCombineDatabase( IN_OUT XrmDatabase source_db, IN_OUT XrmDatabaseMaybe target_db, override )
Bool override
CODE:
XrmCombineDatabase(source_db, &target_db, override);
source_db = NULL; /* source_db is destroyed by XrmCombineDatabase */

void
XrmMergeDatabases(IN_OUT XrmDatabase source_db, IN_OUT XrmDatabaseMaybe target_db )
CODE:
XrmMergeDatabases(source_db, &target_db );
source_db = NULL; /* source_db is destroyed by XrmMergeDatabases */

# can't return Bool (as woule be appropriate); see https://github.com/Perl/perl5/issues/19054
int
XrmGetResource( database, str_name, str_class, OUTLIST char* str_type_return, OUTLIST XrmValue value_return )
XrmDatabase database
const char* str_name
const char* str_class
CODE:
RETVAL = XrmGetResource( database, str_name, str_class, &str_type_return, &value_return );
if ( RETVAL && 0 == strcmp(str_type_return, "String" ) )
value_return.size -= 1; /* don't count the trailiing null */
OUTPUT:
RETVAL

void
XrmPutResource( IN_OUT XrmDatabaseMaybe database, specifier, type, value )
const char* specifier
const char* type
XrmValue &value;
CODE:
/* they said it was a string, so take them at their word and add the
trailing NUL to our count */
if ( 0 == strcmp(type, "String" ) )
value.size += 1;
XrmPutResource( &database, specifier, type, &value );
OUTPUT:
database

void
XrmPutStringResource( IN_OUT XrmDatabaseMaybe database, specifier, value )
const char* specifier
const char* value

void
XrmPutLineResource( IN_OUT XrmDatabaseMaybe database, line )
const char* line

MODULE = X11::Xlib PACKAGE = X11::Xlib::XrmDatabase

void
DESTROY( IN_OUT XrmDatabase database )
CODE:
XrmDestroyDatabase( database );
database = NULL;

MODULE = X11::Xlib PACKAGE = X11::Xlib

# Xcomposite Extension () ----------------------------------------------------

#ifdef XCOMPOSITE_VERSION
Expand Down
5 changes: 5 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ requires 'Test::More' => "0";
requires 'Devel::CheckLib' => "1.03";
requires "ExtUtils::Depends" => "0.405";
requires "Try::Tiny" => "0";

on test => sub {
requires 'Test::TempDir::Tiny';
requires 'Test::More' => 1.001014;
};
138 changes: 138 additions & 0 deletions lib/X11/Xlib.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ my %_functions= (
char_to_keysym codepoint_to_keysym keysym_to_char keysym_to_codepoint )],
fn_pix => [qw( XCreateBitmapFromData XCreatePixmap
XCreatePixmapFromBitmapData XFreePixmap )],
fn_resources => [qw( XResourceManagerString XScreenResourceString
XrmCombineDatabase XrmCombineFileDatabase XrmDestroyDatabase
XrmGetFileDatabase XrmGetResource XrmGetStringDatabase XrmInitialize
XrmLocaleOfDatabase XrmMergeDatabases XrmPutFileDatabase
XrmPutLineResource XrmPutResource XrmPutStringResource XrmSetDatabase )],
fn_screen => [qw( DefaultColormap DefaultDepth DefaultGC DefaultScreen
DefaultVisual DisplayHeight DisplayHeightMM DisplayWidth DisplayWidthMM
RootWindow ScreenCount )],
Expand Down Expand Up @@ -1361,6 +1366,139 @@ Return the key code corresponding to C<$keysym> in the current mapping.

Make the X server emit a sound.

=head2 RESOURCE FUNCTIONS

These functions provide an interface to the X resources manager and databases. Functions
whose first parameter is a databse handle may be used as methods on the handle by importing
L<X11::Xib::XrmDatabase>.

=head3 XrmInitialize

XrmInitialize();

Initialize the resource manager.

=head3 XrmGetFileDatabase

$database = XrmGetFileDatabase( $filename );

Create a resource database from an X resource file.

=head3 XrmPutFileDatabase

XrmPutFileDatabase( $database, $filename );

Write the database to the specified file.

=head3 XResourceManagerString

$string = XResourceManagerString( $display );

Return the C<RESOURCE_MANAGER> property from the root window of screen zero.

=head3 XScreenResourceString

$string = XScreenResourceString( $screen );

Return the C<SCREEN_RESOURCES> property from the root window of the specified screen.

=head3 XrmGetStringDatabase

$database = XrmGetStringDatabase( $data );

Create a new database from resources specified in the string specified in C<$data>. The string
should have the same format as an X resource file.

=head3 XrmLocaleOfDatabase

$string = XrmLocaleOfDatabase( $database );

Return the name of the locale bound to the database.

=head3 XrmDestroyDatabase(database)

XrmDestroyDatabase( $database );

Destroy the specified database. A database is also automatically destroyed when it goes out of scope.

=head3 XrmSetDatabase

XrmSetDatabase( $display, $database );

Associate the resource database with the display.

=head3 XrmGetDatabase

$database = XrmGetDatabase( $display );

Return the database associated with the display.

=head3 XrmCombineFileDatabase

$status = XrmCombineFileDatabase( $filename, $target_db, $override );

Merge the contents of a resource file into a database. If C<$target_db>
is undef or not an existing database, it will be set to a newly
created database.

If C<$override> is true, entries in C<$filename> will replace those in
C<$target_db>.

Returns zero if there is an error.

=head3 XrmCombineDatabase

XrmCombineDatabase( $source_db, $target_db, $override );

Merge the contents of C<$source_db> into C<$target_db>.
If C<$override> is true, entries in C<$source_db> will replace those
in C<$target_db>.

If C<$target_db> is undef or not an existing database, it be set to
C<$source_db>.

C<$source_db> will be invalidated by this function.

=head3 XrmMergeDatabases

XrmMergeDatabases( $source_db, $target_db );

The same as calling L</XrmCombinDatabase> with C<$override = 1>.

=head3 XrmGetResource

($bool, $type, $value ) = XrmGetResource( $database, $name, $class );

Retrieve a resource with the given C<$name> and C<$class>. C<$bool> is true if
the resource was found. If C<$type> is C<String>, C<$value> contains a string.
Otherwise, it is up to the user to decode it,

=head3 XrmPutResource( XrmDatabaseMaybe database, specifier, type, value )

XrmPutResource( $database, $specifier, $type, $value );

Store the resource in the specified database. If C<$database> is
C<undef> or not an existing database, a new one will be created and
the handle stored in C<$database>. If C<$type> is C<String>, the
C<$value> is assumed to be a Perl string and will be stored as a
string, otherwise it is stored as is.

=head3 XrmPutStringResource( XrmDatabaseMaybe database, specifier, value )

XrmPutStringResource( $database, $specifier, $value );

Store the resource as a string the specified database. If C<$database> is
C<undef> or not an existing database, a new one will be created and
the handle stored in C<$database>.

=head3 XrmPutLineResource( XrmDatabaseMaybe database, line )

XrmPutLineResource( $database, $line );

Store the resource record in the database. If C<$database> is
C<undef> or not an existing database, a new one will be created and
the handle stored in C<$database>.

=head2 EXTENSION XCOMPOSITE

This is an optional extension. If you have Xcomposite available when this
Expand Down
Loading