edelib  2.1.0
Public Member Functions | Static Public Member Functions | List of all members
XSettingsClient Class Reference

Client part of XSETTINGS protocol. More...

#include <edelib/XSettingsClient.h>

Public Member Functions

 XSettingsClient ()
 
 ~XSettingsClient ()
 
bool init (Display *dpy, int screen, XSettingsCallback cb=0, void *data=0)
 
void clear (void)
 
void callback (XSettingsCallback cb, void *data=0)
 
int process_xevent (const XEvent *xev)
 
void set (const char *name, int val)
 
void set (const char *name, const char *val)
 
void set (const char *name, unsigned short red, unsigned short green, unsigned short blue, unsigned short alpha)
 
void manager_notify (void)
 

Static Public Member Functions

static bool manager_running (Display *dpy, int screen)
 

Detailed Description

Client part of XSETTINGS protocol.

This class is used to query XSETTINGS data from manager. Due XSETTINGS protocol requirements, manager must already be running. To see differences between official protocol and current implementation, please see XSettingsData documentation.

Before query data, init() must be called. init() will register needed data and (optionaly) register callback for listening changes. This callback will be triggered when one of the settings are changed on manager side so application can update needed data.

Also to get changes via callback, process_xevent() must be placed in loop with X events so XSettingsClient can capture needed events and process them.

This is simple example how stuff should be set up:

* void xsettings_cb(const char* name, XSettingsAction action, XSettingsSetting* setting, void* data) {
* if(strcmp(name, "Test/MySetting") == 0) {
* switch(action) {
* // added setting
* if(setting->type == XSETTING_TYPE_INT)
* printf("Added %s with value %i\n", setting->name, setting->data.v_int);
* if(setting->type == XSETTING_TYPE_STRING)
* printf("Added %s with value %i\n", setting->name, setting->data.v_string);
* // and so on...
* break;
* // changed setting
* // inspect them as for XSETTINGS_ACTION_NEW
* break;
* // deleted setting
* // inspect them as for XSETTINGS_ACTION_NEW
* break;
* }
* }
* return;
* }
*
* // in some function...
*
* XSettingsClient client;
* if(!client.init(fl_display, fl_screen, xsettings_cb)) {
* puts("Unable to init XSETTINGS client");
* return;
* }
*
* XEvent ev;
* while(1) {
* XNextEvent(display, &ev);
* return client.process_xevent(&ev);
* }
*

init() function intentionally have (optional) callback parameter since after calling init(), callback can be triggered immediately if manager is running so XSettingsClient can pick up currently stored settings from it. Alternatively there is callback() function which can be used to change callback during runtime.

Calling callback() before init() is the same as calling init() with callback function.

Note that if callback() is called after init(), settings will not be queried from manager until one of the settings is changed on manager side.

Constructor & Destructor Documentation

Empty constructor

Clears internal data

Member Function Documentation

void callback ( XSettingsCallback  cb,
void *  data = 0 
)

Set callback for listening changes

Parameters
cbis callback parameter
datais data passed to the callback function
void clear ( void  )

Clears internal data. init() must be called agan if other functions are going to be called

bool init ( Display *  dpy,
int  screen,
XSettingsCallback  cb = 0,
void *  data = 0 
)

Init needed communication parts.

Returns
false if failed, true otherwise
Parameters
dpyis display
screenis screen
cbis callback parameter
datais data passed to the callback function
void manager_notify ( void  )

Send changed data to manager. This should be called aftear set()

static bool manager_running ( Display *  dpy,
int  screen 
)
static

Checks if manager is running

Returns
true if does otherwise false
Parameters
dpyis display
screenis screen
int process_xevent ( const XEvent *  xev)

This function should be placed in loop with X events

void set ( const char *  name,
int  val 
)

Set integer value on manager

Parameters
nameis setting name
valis int value
void set ( const char *  name,
const char *  val 
)

Set string (char*) value on manager. Data will be copied

Parameters
nameis setting name
valis string value
void set ( const char *  name,
unsigned short  red,
unsigned short  green,
unsigned short  blue,
unsigned short  alpha 
)

Set RGBA color values on manager

Parameters
nameis setting name
redis red component
greenis green component
blueis blue component
alphais alpha component

The documentation for this class was generated from the following file: