Jabber WindowGram Client (JWGC)

Introduction Screenshots Installation Downloads
Documentation Browse Source Resources Project Site

Stable Version
-none-

Latest Version
beta5



Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

X_driver.c File Reference

#include "mit-copyright.h"
#include "X_driver.h"
#include <X11/Xresource.h>
#include "formatter.h"
#include "mux.h"
#include "variables.h"
#include "error.h"
#include "X_gram.h"
#include "xselect.h"
#include "ulong_dictionary.h"

Go to the source code of this file.

Defines

#define APPNAME   "jwgc"
#define APPCLASS   "Jwgc"
#define NUMBER_OF_OPTIONS   ((sizeof (cmd_options))/ sizeof(cmd_options[0]))

Functions

void xshowinit ()
char * get_string_resource (string name, string class)
int get_bool_resource (string name, string class, int default_value)
unsigned long x_string_to_color (char *name, unsigned long def)
int open_display_and_load_resources (int *pargc, char **argv)
int X_driver_ioerror (Display *display)
void x_get_input ()
int X_driver_init (char *drivername, char notfirst, int *pargc, char **argv)
void X_driver_reset ()
char * X_driver (string text)

Variables

char * app_instance
Display * dpy = NULL


Define Documentation

#define APPCLASS   "Jwgc"
 

Definition at line 57 of file X_driver.c.

Referenced by get_string_resource().

#define APPNAME   "jwgc"
 

Definition at line 49 of file X_driver.c.

Referenced by get_string_resource(), and open_display_and_load_resources().

#define NUMBER_OF_OPTIONS   ((sizeof (cmd_options))/ sizeof(cmd_options[0]))
 

Definition at line 229 of file X_driver.c.

Referenced by open_display_and_load_resources().


Function Documentation

int get_bool_resource string  name,
string  class,
int  default_value
 

Definition at line 129 of file X_driver.c.

References get_string_resource().

00133 {
00134         int result;
00135         char *temp;
00136 
00137         if (!(temp = get_string_resource(name, class)))
00138                 return (default_value);
00139 
00140         result = convert_string_to_bool(temp);
00141         if (result == -1)
00142                 result = default_value;
00143 
00144         return (result);
00145 }

char* get_string_resource string  name,
string  class
 

Definition at line 97 of file X_driver.c.

References APPCLASS, APPNAME, string, string_Concat, string_Concat2, and string_Neq.

00100 {
00101         string full_name, full_class;
00102         int status;
00103         char *type;
00104         XrmValue value;
00105 
00106         full_name = string_Concat(APPNAME, ".");
00107         full_name = string_Concat2(full_name, name);
00108         full_class = string_Concat(APPCLASS, ".");
00109         full_class = string_Concat2(full_class, class);
00110 
00111         status = XrmGetResource(x_resources, full_name, full_class, &type, &value);
00112         free(full_name);
00113         free(full_class);
00114 
00115         if (status != True)
00116                 return (NULL);
00117 
00118         if (string_Neq(type, "String"))
00119                 return (NULL);
00120 
00121         return (value.addr);
00122 }

int open_display_and_load_resources int *  pargc,
char **  argv
 

Definition at line 236 of file X_driver.c.

References APPNAME, dpy, get_string_resource(), getenv(), and NUMBER_OF_OPTIONS.

Referenced by X_driver_init().

00239 {
00240         XrmDatabase temp_db1, temp_db2, temp_db3;
00241         char *filename, *res, *xdef;
00242         char dbasename[128];
00243         extern char *getenv();
00244 
00245         /* Initialize X resource manager: */
00246         XrmInitialize();
00247 
00248         /*
00249          * Parse X toolkit command line arguments (including -display)
00250          * into resources:
00251          */
00252         XrmParseCommand(&x_resources, cmd_options, NUMBER_OF_OPTIONS, APPNAME,
00253                         pargc, argv);
00254 
00255         /*
00256          * Try and open the display using the display specified if given.
00257          * If can't open the display, return an error code.
00258          */
00259         dpy = XOpenDisplay(get_string_resource("display", "display"));
00260         if (!dpy)
00261                 return (1);
00262 
00263         /* Read in our application-specific resources: */
00264         sprintf(dbasename, "%s/jwgc_resources", DATADIR);
00265         temp_db1 = XrmGetFileDatabase(dbasename);
00266 
00267         /*
00268          * Get resources from the just opened display:
00269          */
00270         xdef = XResourceManagerString(dpy);
00271         if (xdef)
00272                 temp_db2 = XrmGetStringDatabase(xdef);
00273         else
00274                 temp_db2 = NULL;
00275 
00276         /*
00277          * Merge the 4 sets of resources together such that when searching
00278          * for resources, they are checking in the following order:
00279          * command arguments, XENVIRONMENT resources, server resources,
00280          * application resources
00281          */
00282         XrmMergeDatabases(temp_db2, &temp_db1);
00283 
00284 #if XlibSpecificationRelease > 4
00285         /* X11 R5 per-screen resources */
00286         res = XScreenResourceString(DefaultScreenOfDisplay(dpy));
00287         if (res != NULL)
00288                 XrmMergeDatabases(XrmGetStringDatabase(res), &temp_db1);
00289 #endif
00290 
00291         /*
00292          * Get XENVIRONMENT resources, if they exist, and merge
00293          */
00294         if ((filename = getenv("XENVIRONMENT"))) {
00295                 temp_db3 = XrmGetFileDatabase(filename);
00296                 XrmMergeDatabases(temp_db3, &temp_db1);
00297         }
00298         XrmMergeDatabases(x_resources, &temp_db1);
00299         x_resources = temp_db1;
00300 
00301         return (0);
00302 }

char* X_driver string  text  ) 
 

Definition at line 388 of file X_driver.c.

References desctype, disp_get_cmds(), dpy, free_desc(), string, string_Copy, and xshow().

00390 {
00391         string text_copy;
00392         desctype *desc;
00393         int numstr, numnl;
00394 
00395         text_copy = string_Copy(text);
00396         desc = disp_get_cmds(text_copy, &numstr, &numnl);
00397 
00398         xshow(dpy, desc, numstr, numnl);
00399 
00400         free(text_copy);
00401         free_desc(desc);
00402         return (NULL);
00403 }

int X_driver_init char *  drivername,
char  notfirst,
int *  pargc,
char **  argv
 

Definition at line 332 of file X_driver.c.

References app_instance, dpy, ERROR, get_bool_resource(), get_string_resource(), mux_add_input_source(), open_display_and_load_resources(), string, string_Copy, ulong_dictionary_Create(), var_set_variable(), X_driver_ioerror(), x_get_input(), x_gram_init(), xicccmInitAtoms(), and xshowinit().

00337 {
00338         string temp;
00339         int sync;
00340 
00341         /*
00342          * Attempt to open display and read resources, including from the
00343          * command line.  If fail, exit with error code, disabling this
00344          * driver:
00345          */
00346         if (open_display_and_load_resources(pargc, argv)) {
00347                 ERROR("Unable to open X display -- disabling X driver.\n");
00348                 return (1);
00349         }
00350 
00351         XSetIOErrorHandler(X_driver_ioerror);
00352 
00353         /*
00354          * For now, set some useful variables using resources:
00355          */
00356         if ((sync = get_bool_resource("synchronous", "Synchronous", 0)))
00357                 XSynchronize(dpy, sync);
00358         if ((temp = get_string_resource("geometry", "Geometry")))
00359                 var_set_variable("default_X_geometry", temp);
00360 
00361         temp = strrchr(argv[0], '/');
00362 
00363         app_instance = string_Copy(temp ? temp + 1 : argv[0]);
00364 
00365         color_dict = ulong_dictionary_Create(37);
00366 
00367         xshowinit();
00368         x_gram_init(dpy);
00369         xicccmInitAtoms(dpy);
00370 
00371         mux_add_input_source(ConnectionNumber(dpy), x_get_input, dpy);
00372 
00373         return (0);
00374 }

int X_driver_ioerror Display *  display  ) 
 

Definition at line 316 of file X_driver.c.

References ERROR2.

Referenced by X_driver_init().

00318 {
00319         ERROR2("X IO error on display '%s'--exiting\n", DisplayString(display));
00320         exit(1);
00321 }

void X_driver_reset  ) 
 

Definition at line 377 of file X_driver.c.

00378 {
00379 }

void x_get_input  ) 
 

Referenced by X_driver_init(), and x_gram_create().

unsigned long x_string_to_color char *  name,
unsigned long  def
 

Definition at line 161 of file X_driver.c.

References dpy, ERROR2, ulong_dictionary_binding, ulong_dictionary_Define(), ulong_dictionary_Delete(), and _ulong_dictionary_binding::value.

00164 {
00165         ulong_dictionary_binding *binding;
00166         int exists;
00167         XColor xc;
00168 
00169         if (name == NULL)
00170                 return (def);
00171 
00172         binding = ulong_dictionary_Define(color_dict, name, &exists);
00173 
00174         if (exists) {
00175                 return ((unsigned long) binding->value);
00176         }
00177         else {
00178                 if (XParseColor(dpy, DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)),
00179                                 name, &xc)) {
00180                         if (XAllocColor(dpy,
00181                         DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)),
00182                                         &xc)) {
00183                                 binding->value = (ulong) xc.pixel;
00184                                 return (xc.pixel);
00185                         }
00186                         else {
00187                                 ERROR2("Error in XAllocColor on \"%s\": using default color\n",
00188                                        name);
00189                         }
00190                 }
00191                 else {
00192                         ERROR2("Error in XParseColor on \"%s\": using default color\n",
00193                                name);
00194                 }
00195                 ulong_dictionary_Delete(color_dict, binding);
00196                 return (def);
00197         }
00198         /* NOTREACHED */
00199 }

void xshowinit  ) 
 

Definition at line 34 of file xshow.c.

Referenced by X_driver_init().

00035 {
00036         desc_context = XUniqueContext();
00037 }


Variable Documentation

char* app_instance
 

Definition at line 29 of file X_driver.c.

Referenced by X_driver_init().

Display* dpy = NULL
 

Definition at line 36 of file X_driver.c.

Referenced by end_xerror_trap(), fixup_and_draw(), get_font(), getLastEvent(), open_display_and_load_resources(), X_driver(), X_driver_init(), x_get_input(), x_gram_create(), x_gram_draw(), x_gram_expose(), x_gram_init(), x_set_icccm_hints(), x_string_to_color(), xcut(), xdestroygram(), xicccmInitAtoms(), xmarkExpose(), xmarkRedraw(), xselGetOwnership(), xselGiveUpOwnership(), xselProcessSelection(), xshow(), and xunmark().



Last updated at Tue Dec 18 21:07:42 PST 2007. This site and project hosted by...SourceForge.net Logo

Source Perspective by Fisheye