From 6a2b84794c16694aaf34b37ba644443ffa106f7f Mon Sep 17 00:00:00 2001 From: Christopher Mosher Date: Tue, 8 Oct 2013 10:29:28 -0400 Subject: [PATCH] conv to SDL2, except video; all untested yet --- configure.ac | 2 +- src/clipboardhandler.cpp | 200 +------------------------------------ src/emulator.cpp | 36 ++++--- src/emulator.h | 2 +- src/gui.cpp | 4 +- src/keyboard.h | 2 +- src/paddlebuttonstates.cpp | 2 +- src/paddles.cpp | 2 +- src/screenimage.cpp | 10 +- src/speakerclicker.cpp | 2 +- src/standardinproducer.cpp | 6 +- 11 files changed, 40 insertions(+), 228 deletions(-) diff --git a/configure.ac b/configure.ac index 5392080..743fc74 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ AM_PROG_CC_C_O # Checks for libraries. -AC_CHECK_LIB([SDL],[SDL_Init],,[AC_MSG_ERROR([cannot find libsdl])]) +AC_CHECK_LIB([SDL2],[SDL_Init],,[AC_MSG_ERROR([cannot find libsdl])]) AC_CHECK_LIB([X11],[XOpenDisplay]) diff --git a/src/clipboardhandler.cpp b/src/clipboardhandler.cpp index 2d73927..1836490 100644 --- a/src/clipboardhandler.cpp +++ b/src/clipboardhandler.cpp @@ -17,214 +17,22 @@ */ #include "clipboardhandler.h" -#include -#include +#include #include -// taken from: http://www.libsdl.org/projects/scrap (original author: Sam Lantinga) - - -/* Determine what type of clipboard we are using */ -#if defined(__WIN32__) || defined(__CYGWIN__) -#define WIN_SCRAP -#elif defined(__unix__) -#define X11_SCRAP -#else -#error Unknown window manager for clipboard handling -#endif /* scrap type */ - - - -/* System dependent variables */ -#if defined(X11_SCRAP) -static Display *SDL_Display; -static Window SDL_Window; -static void (*Lock_Display)(); -static void (*Unlock_Display)(); -#elif defined(WIN_SCRAP) -static HWND SDL_Window; -#endif /* scrap type */ -static bool initialized(false); -static bool have(false); - - -#ifdef X11_SCRAP -static int clipboard_filter(const SDL_Event *event) -{ - /* Post all non-window manager specific events */ - if ( event->type != SDL_SYSWMEVENT ) { - return(1); - } - - /* Handle window-manager specific clipboard events */ - switch (event->syswm.msg->event.xevent.type) { - /* Copy the selection from XA_CUT_BUFFER0 to the requested property */ - case SelectionRequest: { - XSelectionRequestEvent *req; - XEvent sevent; - int seln_format; - unsigned long nbytes; - unsigned long overflow; - unsigned char *seln_data; - - req = &event->syswm.msg->event.xevent.xselectionrequest; - sevent.xselection.type = SelectionNotify; - sevent.xselection.display = req->display; - sevent.xselection.selection = req->selection; - sevent.xselection.target = None; - sevent.xselection.property = None; - sevent.xselection.requestor = req->requestor; - sevent.xselection.time = req->time; - if ( XGetWindowProperty(SDL_Display, DefaultRootWindow(SDL_Display), - XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, - &sevent.xselection.target, &seln_format, - &nbytes, &overflow, &seln_data) == Success ) - { - if ( sevent.xselection.target == req->target ) - { - if ( sevent.xselection.target == XA_STRING ) - { - if ( seln_data[nbytes-1] == '\0' ) - --nbytes; - } - XChangeProperty(SDL_Display, req->requestor, req->property, - sevent.xselection.target, seln_format, PropModeReplace, - seln_data, nbytes); - sevent.xselection.property = req->property; - } - XFree(seln_data); - } - XSendEvent(SDL_Display,req->requestor,False,0,&sevent); - XSync(SDL_Display, False); - } - break; - } - - /* Post the event for X11 clipboard reading above */ - return(1); -} -#endif /* X11_SCRAP */ - - - - ClipboardHandler::ClipboardHandler() { - if (initialized) - return; - initialized = true; - - SDL_SetError("SDL is not running on known window manager"); - - /* Grab the window manager specific information */ - SDL_SysWMinfo info; - SDL_VERSION(&info.version); - if (SDL_GetWMInfo(&info)) - { - /* Save the information for later use */ -#if defined(X11_SCRAP) - if (info.subsystem == SDL_SYSWM_X11) - { - SDL_Display = info.info.x11.display; - SDL_Window = info.info.x11.window; - Lock_Display = info.info.x11.lock_func; - Unlock_Display = info.info.x11.unlock_func; - - /* Enable the special window hook events */ - SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); - SDL_SetEventFilter(clipboard_filter); - - have = true; - } - else - { - SDL_SetError("SDL is not running on X11"); - } -#elif defined(WIN_SCRAP) - SDL_Window = info.window; - have = true; -#endif /* scrap type */ - } } - ClipboardHandler::~ClipboardHandler() { } - std::string ClipboardHandler::getText() { std::string ret; - if (!have) - return ret; - -#if defined(X11_SCRAP) - const Atom format(XA_STRING); - - Atom selection; - Lock_Display(); - Window owner = XGetSelectionOwner(SDL_Display, XA_PRIMARY); - Unlock_Display(); - if (owner == None || owner == SDL_Window) - { - owner = DefaultRootWindow(SDL_Display); - selection = XA_CUT_BUFFER0; - } - else - { - int selection_response = 0; - SDL_Event event; - - owner = SDL_Window; - Lock_Display(); - selection = XInternAtom(SDL_Display, "SDL_SELECTION", False); - XConvertSelection(SDL_Display, XA_PRIMARY, format, selection, owner, CurrentTime); - Unlock_Display(); - while (!selection_response) - { - SDL_WaitEvent(&event); - if (event.type == SDL_SYSWMEVENT) - { - XEvent xevent = event.syswm.msg->event.xevent; - - if (xevent.type == SelectionNotify && xevent.xselection.requestor == owner) - selection_response = 1; - } - } - } - - - - Lock_Display(); - Atom seln_type; - int seln_format; - unsigned long nbytes; - unsigned long overflow; - char *src; - if (XGetWindowProperty(SDL_Display, owner, selection, 0, INT_MAX/4, False, format, &seln_type, &seln_format, &nbytes, &overflow, (unsigned char **)&src) == Success) - { - if (seln_type == format) - { - ret.assign(src,nbytes); - } - XFree(src); - } - Unlock_Display(); -#elif defined(WIN_SCRAP) - const UINT format(CF_TEXT); - if (IsClipboardFormatAvailable(format) && OpenClipboard(SDL_Window)) - { - const HANDLE hMem = GetClipboardData(format); - if (hMem) - { - char *src = (char*)GlobalLock(hMem); - ret.assign(src); - GlobalUnlock(hMem); - } - CloseClipboard(); - } -#endif /* scrap type */ - + char* sdlAllocatedText = SDL_GetClipboardText(); + ret.assign(sdlAllocatedText); + SDL_free(sdlAllocatedText); return ret; } diff --git a/src/emulator.cpp b/src/emulator.cpp index c1205c4..01923a4 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -19,7 +19,7 @@ #include "configep2.h" #include "e2const.h" -#include +#include #include @@ -205,11 +205,11 @@ int Emulator::run() void Emulator::dispatchKeyUp(const SDL_KeyboardEvent& keyEvent) { - unsigned char key = (unsigned char)(keyEvent.keysym.unicode & 0x7F); - SDLKey sym = keyEvent.keysym.sym; - SDLMod mod = keyEvent.keysym.mod; - unsigned char scancode = keyEvent.keysym.scancode; -// printf("key UP: %d sym: %d mod: %04X scn: %d\n",key,sym,mod,scancode); + SDL_Keycode sym = keyEvent.keysym.sym; + SDL_Keymod mod = (SDL_Keymod)keyEvent.keysym.mod; + unsigned char key = (unsigned char)(sym & 0x7F); + + // printf("key UP: %d sym: %d mod: %04X scn: %d\n",key,sym,mod,scancode); if ((sym < 0x7F || sym == SDLK_LEFT || sym == SDLK_RIGHT) && !(sym == SDLK_TAB || sym == SDLK_BACKQUOTE || sym == '[' || sym == '\\' || sym == SDLK_DELETE) && @@ -230,10 +230,14 @@ void Emulator::dispatchKeyUp(const SDL_KeyboardEvent& keyEvent) // Apple ][ or Apple ][ plus keyboard void Emulator::dispatchKeypress(const SDL_KeyboardEvent& keyEvent) { - unsigned char key = (unsigned char)(keyEvent.keysym.unicode & 0x7F); - SDLKey sym = keyEvent.keysym.sym; - SDLMod mod = keyEvent.keysym.mod; - unsigned char scancode = keyEvent.keysym.scancode; + if (keyEvent.repeat) + { + return; + } + + SDL_Keycode sym = keyEvent.keysym.sym; + SDL_Keymod mod = (SDL_Keymod)keyEvent.keysym.mod; + unsigned char key = (unsigned char)(sym & 0x7F); // printf("key DN: %d sym: %d mod: %04X scn: %d\n",key,sym,mod,scancode); @@ -339,7 +343,7 @@ void Emulator::dispatchKeypress(const SDL_KeyboardEvent& keyEvent) return; } // ...else save a screen shot - else if (sym == SDLK_PRINT) + else if (sym == SDLK_PRINTSCREEN) { this->screenImage.saveBMP(); } @@ -360,10 +364,10 @@ void Emulator::dispatchKeypress(const SDL_KeyboardEvent& keyEvent) // Ctrl-Shift-Space is the same as Space key = ' '; } - else if ((mod&KMOD_CTRL) && !(mod&KMOD_SHIFT) && SDLK_KP0 <= sym && sym <= SDLK_KP9) + else if ((mod&KMOD_CTRL) && !(mod&KMOD_SHIFT) && SDLK_KP_0 <= sym && sym <= SDLK_KP_9) { // Control-only numeric keypad keys are converted to regular digit keys - key = sym-SDLK_KP0+'0'; + key = sym-SDLK_KP_0+'0'; } else if ((mod&KMOD_CTRL) && !(mod&KMOD_SHIFT) && (('0' <= sym && sym <= '9') || sym == '/' || sym == ' ')) { @@ -401,8 +405,10 @@ void Emulator::dispatchKeypress(const SDL_KeyboardEvent& keyEvent) // window void Emulator::cmdKey(const SDL_KeyboardEvent& keyEvent) { - unsigned char key = (unsigned char)(keyEvent.keysym.unicode & 0x7F); - SDLKey sym = keyEvent.keysym.sym; + SDL_Keycode sym = keyEvent.keysym.sym; + SDL_Keymod mod = (SDL_Keymod)keyEvent.keysym.mod; + unsigned char key = (unsigned char)(sym & 0x7F); + if (sym == SDLK_RETURN) { processCommand(); diff --git a/src/emulator.h b/src/emulator.h index 35b5181..4dd0006 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -27,7 +27,7 @@ #include "keyboardbuffermode.h" #include "hypermode.h" #include "clipboardhandler.h" -#include +#include class Timable; class Config; diff --git a/src/gui.cpp b/src/gui.cpp index a38e51f..344a292 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -20,7 +20,7 @@ #endif #include "gui.h" -#include +#include // Create, initialize, and cable together the UI objects to serve this // program @@ -33,9 +33,7 @@ GUI::GUI() throw GUI::NotInitException(); } - SDL_EnableUNICODE(1); SDL_ShowCursor(0); - SDL_EnableKeyRepeat(0,0); } GUI::~GUI() diff --git a/src/keyboard.h b/src/keyboard.h index 014ca3c..f4fbd17 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -18,7 +18,7 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -#include +#include #include typedef std::queue KeypressQueue; diff --git a/src/paddlebuttonstates.cpp b/src/paddlebuttonstates.cpp index 9528a5f..689eeaa 100644 --- a/src/paddlebuttonstates.cpp +++ b/src/paddlebuttonstates.cpp @@ -17,7 +17,7 @@ */ #include "paddlebuttonstates.h" -#include +#include const int PaddleButtonStates::PADDLE_COUNT(3); diff --git a/src/paddles.cpp b/src/paddles.cpp index e1655fa..bed20dd 100644 --- a/src/paddles.cpp +++ b/src/paddles.cpp @@ -17,7 +17,7 @@ */ #include "e2const.h" #include "paddles.h" -#include +#include #include #include diff --git a/src/screenimage.cpp b/src/screenimage.cpp index f0dd6e1..b106fd5 100644 --- a/src/screenimage.cpp +++ b/src/screenimage.cpp @@ -20,7 +20,7 @@ #include "applentsc.h" #include "card.h" #include "util.h" -#include +#include #include #include @@ -67,7 +67,7 @@ void ScreenImage::toggleFullScreen() void ScreenImage::createScreen() { - this->screen = SDL_SetVideoMode(SCRW,SCRH,32,SDL_HWSURFACE|SDL_HWPALETTE|(this->fullscreen?SDL_FULLSCREEN:0)); +// TODO this->screen = SDL_SetVideoMode(SCRW,SCRH,32,SDL_HWSURFACE|SDL_HWPALETTE|(this->fullscreen?SDL_FULLSCREEN:0)); if (this->screen == NULL) { printf("Unable to set video mode: %s\n",SDL_GetError()); @@ -248,7 +248,7 @@ void ScreenImage::drawChar(const char ch, int row, int col, int color, int bgcol pn -= FONTW; pn += SCRW; } - SDL_UpdateRect(this->screen,col*FONTW,row*FONTH,(col+1)*FONTW,(row+1)*FONTH); +// TODO SDL_UpdateRect(this->screen,col*FONTW,row*FONTH,(col+1)*FONTW,(row+1)*FONTH); } void ScreenImage::displayHz(int hz) @@ -296,7 +296,7 @@ void ScreenImage::drawPower(bool on) pn -= POWERD; pn += this->screen->pitch/4; } - SDL_UpdateRect(this->screen,0,HEIGHT,POWERD,HEIGHT+POWERD); +// TODO SDL_UpdateRect(this->screen,0,HEIGHT,POWERD,HEIGHT+POWERD); } ScreenImage::~ScreenImage() @@ -305,7 +305,7 @@ ScreenImage::~ScreenImage() void ScreenImage::notifyObservers() { - SDL_UpdateRect(this->screen,0,0,SCRW,SCRH); +// TODO SDL_UpdateRect(this->screen,0,0,SCRW,SCRH); } void ScreenImage::setElem(unsigned int i, const unsigned int val) diff --git a/src/speakerclicker.cpp b/src/speakerclicker.cpp index 997be80..b54336a 100644 --- a/src/speakerclicker.cpp +++ b/src/speakerclicker.cpp @@ -16,7 +16,7 @@ along with this program. If not, see . */ #include "speakerclicker.h" -#include +#include #include #include #include diff --git a/src/standardinproducer.cpp b/src/standardinproducer.cpp index 6d379f9..15c9f85 100644 --- a/src/standardinproducer.cpp +++ b/src/standardinproducer.cpp @@ -16,8 +16,8 @@ along with this program. If not, see . */ #include "standardinproducer.h" -#include -#include +#include +#include #include #define CR '\r' @@ -92,7 +92,7 @@ static int readInput(void *voidkeys) StandardInProducer::StandardInProducer() { - SDL_CreateThread(readInput,&this->keys); + SDL_CreateThread(readInput,"stdin",&this->keys); } StandardInProducer::~StandardInProducer()