DDIO: implement mouse grab state functions

Hide global variable ddio_mouseGrabbed.
This commit is contained in:
Azamat H. Hackimov 2024-08-21 12:29:28 +03:00
parent 45ff821328
commit 39e971504e
5 changed files with 21 additions and 103 deletions

View File

@ -37,6 +37,7 @@
#include "program.h"
#include "dedicated_server.h"
#include "descent.h"
#include "ddio.h"
#include "application.h"
#include "appdatabase.h"
#include "args.h"
@ -45,16 +46,12 @@
#include "osiris_dll.h"
extern bool ddio_mouseGrabbed;
std::filesystem::path orig_pwd;
bool linux_permit_gamma = false;
static volatile char already_tried_signal_cleanup = 0;
void ddio_InternalClose(); // needed for emergency cleanup.
void just_exit(void) {
ddio_InternalClose(); // try to reset serial port.
@ -289,18 +286,14 @@ int main(int argc, char *argv[]) {
if (FindArgChar("-nomousegrab", 'm')) {
flags |= APPFLAG_NOMOUSECAPTURE;
ddio_MouseSetGrab(false);
}
ddio_mouseGrabbed = (FindArgChar("-nomousegrab", 'm') == 0);
SDL_SetRelativeMouseMode(ddio_MouseGetGrab() ? SDL_TRUE : SDL_FALSE);
if (!FindArg("-sharedmemory")) {
flags |= APPFLAG_NOSHAREDMEMORY;
}
flags |= APPFLAG_WINDOWEDMODE;
if (!FindArg("-nodgamouse")) {
flags |= APPFLAG_DGAMOUSE;
}
#else
fprintf(stderr, "Error: \"--dedicated\" or \"-d\" flag required\n");
return 0;

View File

@ -257,6 +257,12 @@ void ddio_InternalResetKey(uint8_t key);
bool ddio_MouseInit();
void ddio_MouseClose();
/// Get mouse grab state
bool ddio_MouseGetGrab();
/// Set mouse grab state
void ddio_MouseSetGrab(bool grab);
// get device caps
int ddio_MouseGetCaps(int *btn, int *axis);

View File

@ -70,8 +70,6 @@
#include "pserror.h"
extern bool ddio_mouseGrabbed;
extern volatile struct tLnxKeys {
union {
int up_ticks;
@ -354,8 +352,9 @@ int sdlKeyFilter(const SDL_Event *event) {
if (event->key.keysym.mod & KMOD_CTRL) {
switch (kc) {
case KEY_G: // toggle grabbed input.
ddio_mouseGrabbed = !ddio_mouseGrabbed;
SDL_SetRelativeMouseMode(ddio_mouseGrabbed ? SDL_TRUE : SDL_FALSE);
bool grab = !ddio_MouseGetGrab();
ddio_MouseSetGrab(grab);
SDL_SetRelativeMouseMode((SDL_bool)grab);
return 0;
} // switch
} // if

View File

@ -89,7 +89,7 @@
#include "ddio.h"
#include "ddio_lnx.h"
bool ddio_mouseGrabbed = false;
static bool ddio_mouseGrabbed = true;
static bool DDIO_mouse_init = false;
static struct mses_state {
@ -125,6 +125,14 @@ bool ddio_MouseInit(void) {
return true;
}
bool ddio_MouseGetGrab() {
return ddio_mouseGrabbed;
}
void ddio_MouseSetGrab(bool grab) {
ddio_mouseGrabbed = grab;
}
int ddio_MouseGetCaps(int *buttons, int *axes) {
*buttons = 6;
*axes = 2;
@ -159,22 +167,6 @@ void ddio_MouseReset() {
// reset button states
ddio_MouseQueueFlush();
/*
if(Mouse_mode==MOUSE_STANDARD_MODE)
return;
bool use_dga = false;
if(Lnx_app_obj && Lnx_app_obj->m_Flags&APPFLAG_DGAMOUSE)
use_dga = true;
// warp the mouse.
if(!use_dga)
{
XWarpPointer(Lnx_app_obj->m_Display, None, Lnx_app_obj->m_Window,
0,0,0,0, Lnx_app_obj->m_W/2, Lnx_app_obj->m_H/2);
}
*/
DDIO_mouse_state.x = DDIO_mouse_state.cx = Lnx_app_obj->m_W / 2;
DDIO_mouse_state.y = DDIO_mouse_state.cy = Lnx_app_obj->m_H / 2;
DDIO_mouse_state.dy = DDIO_mouse_state.dx = 0;
@ -395,68 +387,6 @@ int sdlMouseWheelFilter(SDL_Event const *event) {
}
int sdlMouseMotionFilter(SDL_Event const *event) {
/*
int oldmx, oldmy;
int deltamx,deltamy;
oldmx = DDIO_mouse_state.cx;
oldmy = DDIO_mouse_state.cy;
deltamx = deltamy = 0;
bool use_dga = false;
if(Lnx_app_obj->m_Flags&APPFLAG_DGAMOUSE)
use_dga = true;
if(Mouse_mode==MOUSE_STANDARD_MODE)
return;
while (XCheckMaskEvent(Lnx_app_obj->m_Display, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, &evt))
{
switch (evt.type)
{
case MotionNotify:
if(use_dga)
{
deltamx += event->motion.x; //evt.xmotion.x_root;
deltamy += event->motion.y; //evt.xmotion.y_root;
}else
{
if ((evt.xmotion.x != DDIO_mouse_state.cx) && (evt.xmotion.y != DDIO_mouse_state.cy)) {
deltamx += (evt.xmotion.x - oldmx);
deltamy += (evt.xmotion.y - oldmy);
oldmx = evt.xmotion.x;
oldmy = evt.xmotion.y;
}
}
break;
case ButtonPress:
case ButtonRelease:
break;
}
}
if( (deltamx) || (deltamy) )
{
DDIO_mouse_state.dx = deltamx;
DDIO_mouse_state.dy = deltamy;
DDIO_mouse_state.x += deltamx;
DDIO_mouse_state.y += deltamy;
if (DDIO_mouse_state.x < DDIO_mouse_state.l) DDIO_mouse_state.x = DDIO_mouse_state.l;
if (DDIO_mouse_state.x >= DDIO_mouse_state.r) DDIO_mouse_state.x = DDIO_mouse_state.r-1;
if (DDIO_mouse_state.y < DDIO_mouse_state.t) DDIO_mouse_state.y = DDIO_mouse_state.t;
if (DDIO_mouse_state.y >= DDIO_mouse_state.b) DDIO_mouse_state.y = DDIO_mouse_state.b-1;
// warp the mouse.
if(!use_dga)
{
XWarpPointer(Lnx_app_obj->m_Display, None, Lnx_app_obj->m_Window,
0,0,0,0, Lnx_app_obj->m_W/2, Lnx_app_obj->m_H/2);
}
}
*/
if (event->type == SDL_JOYBALLMOTION) {
DDIO_mouse_state.dx = event->jball.xrel / 100;
DDIO_mouse_state.dy = event->jball.yrel / 100;

View File

@ -343,16 +343,12 @@ void opengl_SetDefaults() {
extern bool linux_permit_gamma;
extern renderer_preferred_state Render_preferred_state;
extern bool ddio_mouseGrabbed;
int SDLCALL d3SDLEventFilter(void *userdata, SDL_Event *event);
int opengl_Setup(oeApplication *app, int *width, int *height) {
int winw = Video_res_list[Game_video_resolution].width;
int winh = Video_res_list[Game_video_resolution].height;
// rcg09182000 don't need to quitsubsystem anymore...
// SDL_QuitSubSystem(SDL_INIT_VIDEO); // here goes nothing...
// Already_loaded = false;
SDL_ClearError();
if (!SDL_WasInit(SDL_INIT_VIDEO)) {
const int rc = SDL_Init(SDL_INIT_VIDEO);
@ -521,12 +517,6 @@ int opengl_Setup(oeApplication *app, int *width, int *height) {
return 0;
}
if (!FindArg("-nomousegrab")) {
ddio_mouseGrabbed = true;
}
SDL_SetRelativeMouseMode(ddio_mouseGrabbed ? SDL_TRUE : SDL_FALSE);
// rcg09182000 gamma fun.
// rcg01112000 --nogamma fun.
if (FindArgChar("-nogamma", 'M')) {