00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Core/precomp.h"
00020
00021 #ifdef USE_X11
00022
00023 #include "implementation_xwindow.h"
00024 #include "API/Display/Display/display.h"
00025 #include "Display/Display/X11/display_xwindow.h"
00026 #include "API/Display/Input/input.h"
00027 #include "Display/Input/X11/mouse_x11.h"
00028 #include "Display/Input/X11/keyboard_x11.h"
00029 #include "Display/Input/X11/joystick_linux.h"
00030 #include "implementation.h"
00031
00032
00033 extern "C"
00034 {
00035 DL_PREFIX char* clan_module_identify()
00036 {
00037 return "Native X11 target";
00038 }
00039
00040 DL_PREFIX char* clan_module_abbreviation()
00041 {
00042 return "x11";
00043 }
00044
00045 DL_PREFIX void clan_module_init()
00046 {
00047 CL_Implementation_XWindow::add_display();
00048 }
00049 }
00050
00051 char* xwindow_identify()
00052 {
00053 return clan_module_identify();
00054 }
00055
00056 char* xwindow_abbreviation()
00057 {
00058 return clan_module_abbreviation();
00059 }
00060
00061 void xwindow_init()
00062 {
00063 clan_module_init();
00064 }
00065
00066 bool CL_Implementation_XWindow::initialized = false;
00067 Display *CL_Implementation_XWindow::dpy = NULL;
00068 Window CL_Implementation_XWindow::root;
00069 int CL_Implementation_XWindow::default_scr;
00070 int CL_Implementation_XWindow::display_counter=0;
00071
00072 static CL_Implementation_XWindow impl_xwindow;
00073
00074 CL_Implementation_XWindow::~CL_Implementation_XWindow()
00075 {
00076 while (display_counter > 0) clean_up();
00077 }
00078
00079 bool CL_Implementation_XWindow::init()
00080 {
00081 if (initialized) return true;
00082
00083 dpy = XOpenDisplay(NULL);
00084 if (dpy == NULL) return false;
00085
00086 default_scr = DefaultScreen(dpy);
00087 root = RootWindow(dpy, default_scr);
00088
00089 return true;
00090 }
00091
00092 void CL_Implementation_XWindow::clean_up()
00093 {
00094 if (display_counter == 0) return;
00095
00096 display_counter--;
00097 if (display_counter>0) return;
00098
00099 XCloseDisplay(dpy);
00100 }
00101
00102 void CL_Implementation_XWindow::add_display()
00103 {
00104 if (init() == false)
00105 {
00106 std::cout << "ClanLib: Failed to open display. No XWindow display available."
00107 << std::endl;
00108 }
00109
00110 CL_XWindow_DisplayCard *card = new CL_XWindow_DisplayCard(
00111 dpy,
00112 root,
00113 display_counter);
00114
00115 CL_Display::cards.push_back(card);
00116
00117 CL_Input::keyboards.push_back(new CL_XWindowKeyboard(card));
00118 CL_Input::pointers.push_back(new CL_Mouse_XWin(card));
00119
00120 #ifdef USE_JOY
00121 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
00122
00123 for (int i=0; i<8; i++)
00124 {
00125 CL_LinuxJoystick *joy = new CL_LinuxJoystick();
00126 if (joy->init(i))
00127 CL_Input::joysticks.push_back(joy);
00128 else
00129 delete joy;
00130 }
00131
00132 #endif
00133 #endif
00134
00135 display_counter+=3;
00136 }
00137
00138 #endif