Move some X stuff to x.c.

SVN revision: 34143
This commit is contained in:
Kim Woelders 2008-03-29 10:48:45 +00:00
parent c363642d11
commit ce8c78830a
7 changed files with 69 additions and 44 deletions

View File

@ -570,8 +570,6 @@ const char *FontLookup(const char *name);
/* handlers.c */
void SignalsSetup(void);
void SignalsRestore(void);
void HandleXError(Display * d, XErrorEvent * ev);
void HandleXIOError(Display * d);
/* main.c */
void EExit(int exitcode);
@ -616,7 +614,6 @@ char **ThemesList(int *num);
extern const char e_wm_name[];
extern const char e_wm_version[];
extern const char e_wm_date[];
__EXPORT__ extern Display *disp;
extern RealRoot RRoot;
__EXPORT__ extern VirtRoot VRoot;
__EXPORT__ extern EConf Conf;

View File

@ -30,18 +30,20 @@
static Window
ExtInitWinMain(void)
{
int i, err;
Ecore_X_Window win;
XGCValues gcv;
GC gc;
Pixmap pmap, mask;
Atom a;
int i;
XSetWindowAttributes attr;
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("ExtInitWinMain enter\n");
disp = EDisplayOpen(NULL, -1);
err = EDisplayOpen(NULL, -1);
if (err)
return None;
EGrabServer();

View File

@ -23,10 +23,8 @@
*/
#include "E.h"
#include "session.h"
#include "xwin.h"
#include <sys/wait.h>
#include <signal.h>
#include <X11/Xproto.h>
static void
SignalHandler(int sig)
@ -175,26 +173,3 @@ SignalsRestore(void)
/* This function will restore all the signal handlers for E */
doSignalsSetup(0);
}
void
HandleXError(Display * d __UNUSED__, XErrorEvent * ev)
{
char buf[64];
if (EDebug(1))
{
XGetErrorText(disp, ev->error_code, buf, 63);
Eprintf("*** ERROR: xid=%#lx error=%i req=%i/%i: %s\n",
ev->resourceid, ev->error_code,
ev->request_code, ev->minor_code, buf);
}
Mode.events.last_error_code = ev->error_code;
}
void
HandleXIOError(Display * d __UNUSED__)
{
disp = NULL;
SessionExit(EEXIT_ERROR, NULL);
}

View File

@ -47,7 +47,6 @@ const char e_wm_name[] = "Enlightenment";
const char e_wm_version[] = VERSION;
const char e_wm_date[] = E_CHECKOUT_DATE;
Display *disp;
RealRoot RRoot;
VirtRoot VRoot;
EConf Conf;

View File

@ -25,16 +25,24 @@
#include "events.h"
#include "ewins.h"
#include "screen.h"
#include "session.h"
#include "xwin.h"
#include <signal.h>
#include <X11/keysym.h>
static void
HandleXIOError(void)
{
SessionExit(EEXIT_ERROR, NULL);
}
/*
* This function sets up all of our connections to X
*/
void
SetupX(const char *dstr)
{
int err;
char buf[128];
long mask;
@ -44,8 +52,8 @@ SetupX(const char *dstr)
dstr = ":0";
/* Open a connection to the diplay nominated by the DISPLAY variable */
disp = EDisplayOpen(dstr, VRoot.scr);
if (!disp)
err = EDisplayOpen(dstr, VRoot.scr);
if (err)
{
Alert(_("Enlightenment cannot connect to the display nominated by\n"
"your shell's DISPLAY environment variable. You may set this\n"
@ -103,7 +111,7 @@ SetupX(const char *dstr)
#ifdef SIGSTOP
kill(getpid(), SIGSTOP);
#endif
disp = EDisplayOpen(dstr, i);
EDisplayOpen(dstr, i);
/* Terminate the loop as I am the child process... */
break;
}
@ -113,10 +121,7 @@ SetupX(const char *dstr)
Mode.display.name = Estrdup(DisplayString(disp));
Esetenv("DISPLAY", Mode.display.name);
/* set up an error handler for then E would normally have fatal X errors */
XSetErrorHandler((XErrorHandler) HandleXError);
/* set up a handler for when the X Connection goes down */
XSetIOErrorHandler((XIOErrorHandler) HandleXIOError);
EDisplaySetErrorHandlers(HandleXIOError);
/* Root defaults */
RROOT = ERegisterWindow(DefaultRootWindow(disp), NULL);

53
src/x.c
View File

@ -40,6 +40,8 @@
#define DEBUG_XWIN 0
#define DEBUG_PIXMAP 0
Display *disp = NULL;
#if USE_COMPOSITE
static Visual *argb_visual = NULL;
static Colormap argb_cmap = None;
@ -1677,11 +1679,10 @@ EWindowGetShapePixmap(Win win)
* Display
*/
Display *
int
EDisplayOpen(const char *dstr, int scr)
{
char dbuf[256], *s;
Display *dpy;
if (scr >= 0)
{
@ -1700,12 +1701,12 @@ EDisplayOpen(const char *dstr, int scr)
#ifdef USE_ECORE_X
ecore_x_init(dstr);
dpy = ecore_x_display_get();
disp = ecore_x_display_get();
#else
dpy = XOpenDisplay(dstr);
disp = XOpenDisplay(dstr);
#endif
return dpy;
return (disp) ? 0 : -1;
}
void
@ -1739,6 +1740,48 @@ EDisplayDisconnect(void)
disp = NULL;
}
static int
HandleXError(Display * dpy, XErrorEvent * ev)
{
char buf[64];
if (EDebug(1))
{
XGetErrorText(dpy, ev->error_code, buf, 63);
Eprintf("*** ERROR: xid=%#lx error=%i req=%i/%i: %s\n",
ev->resourceid, ev->error_code,
ev->request_code, ev->minor_code, buf);
}
Mode.events.last_error_code = ev->error_code;
return 0;
}
static void (*EXIOErrorFunc) (void) = NULL;
static int
HandleXIOError(Display * dpy __UNUSED__)
{
disp = NULL;
if (EXIOErrorFunc)
EXIOErrorFunc();
return 0;
}
void
EDisplaySetErrorHandlers(void (*fatal) (void))
{
/* set up an error handler for then E would normally have fatal X errors */
XSetErrorHandler(HandleXError);
/* set up a handler for when the X Connection goes down */
EXIOErrorFunc = fatal;
XSetIOErrorHandler(HandleXIOError);
}
/*
* Server
*/

View File

@ -26,10 +26,14 @@
#include <X11/Xlib.h>
#include <X11/extensions/shape.h>
#include "util.h"
Display *EDisplayOpen(const char *dstr, int scr);
__EXPORT__ extern Display *disp;
int EDisplayOpen(const char *dstr, int scr);
void EDisplayClose(void);
void EDisplayDisconnect(void);
void EDisplaySetErrorHandlers(void (*fatal) (void));
void EGrabServer(void);
void EUngrabServer(void);