Skip to content

Commit

Permalink
gui: more explicit joystick handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hanatos committed Feb 22, 2022
1 parent 5a9ddaa commit 00a8e56
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ typedef struct dt_gui_wstate_t
char notification_msg[256]; // message to display

int fullscreen_view; // darkroom mode without panels

int have_joystick; // found and enabled a joystick (disable via gui/disable_joystick in config)
}
dt_gui_wstate_t;

Expand Down
17 changes: 16 additions & 1 deletion src/gui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,22 @@ int main(int argc, char *argv[])
pthread_t joystick_thread;
const int joystick_present = glfwJoystickPresent(GLFW_JOYSTICK_1);
if(joystick_present)
pthread_create(&joystick_thread, 0, joystick_active, 0);
{
const char *name = glfwGetJoystickName(GLFW_JOYSTICK_1);
dt_log(s_log_gui, "found joystick %s", name);
const int disable = dt_rc_get_int(&vkdt.rc, "gui/disable_joystick", 0);
if(disable)
{
vkdt.wstate.have_joystick = 0;
dt_log(s_log_gui, "disabling joystick due to explicit config request");
}
else
{
vkdt.wstate.have_joystick = 1;
pthread_create(&joystick_thread, 0, joystick_active, 0);
}
}
else dt_log(s_log_gui, "no joysticks found");

// main loop
vkdt.graph_dev.frame = vkdt.state.anim_frame = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/gui/render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ void render_lighttable_center(double &hotkey_time)
{ // center image view
{ // assign star rating/colour labels via gamepad:
int /*axes_cnt = 0,*/ butt_cnt = 0;
const uint8_t* butt = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &butt_cnt);
// const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_cnt);
const uint8_t* butt = vkdt.wstate.have_joystick ? glfwGetJoystickButtons(GLFW_JOYSTICK_1, &butt_cnt) : 0;
// const float* axes = vkdt.wstate.have_joystick ? glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_cnt) : 0;
static double gamepad_time = ImGui::GetTime();
if(butt && butt[2]) // triangle
if(ImGui::GetTime() - gamepad_time > 0.1)
Expand Down Expand Up @@ -1162,8 +1162,8 @@ inline void draw_widget(int modid, int parid)
double time_now = ImGui::GetTime();
static double gamepad_time = ImGui::GetTime();
int axes_cnt = 0, butt_cnt = 0;
const uint8_t *butt = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &butt_cnt);
const float *axes = glfwGetJoystickAxes (GLFW_JOYSTICK_1, &axes_cnt);
const uint8_t *butt = vkdt.wstate.have_joystick ? glfwGetJoystickButtons(GLFW_JOYSTICK_1, &butt_cnt) : 0;
const float *axes = vkdt.wstate.have_joystick ? glfwGetJoystickAxes (GLFW_JOYSTICK_1, &axes_cnt) : 0;
static int gamepad_reset = 0;
if(time_now - gamepad_time > 0.1 && butt && butt[12])
{
Expand Down Expand Up @@ -1430,7 +1430,7 @@ inline void draw_widget(int modid, int parid)
}
}
int axes_cnt = 0;
const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_cnt);
const float* axes = vkdt.wstate.have_joystick ? glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_cnt) : 0;
const float scale = vkdt.state.scale > 0.0f ? vkdt.state.scale : 1.0f;
#define SMOOTH(X) copysignf(MAX(0.0f, fabsf(X) - 0.05f), X)
if(vkdt.wstate.selected >= 0 && axes)
Expand Down Expand Up @@ -1978,8 +1978,8 @@ void render_darkroom_pipeline()
void render_darkroom()
{
int axes_cnt = 0, butt_cnt = 0;
const uint8_t* butt = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &butt_cnt);
const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_cnt);
const uint8_t *butt = vkdt.wstate.have_joystick ? glfwGetJoystickButtons(GLFW_JOYSTICK_1, &butt_cnt) : 0;
const float *axes = vkdt.wstate.have_joystick ? glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_cnt) : 0;
{ // center image view
int win_x = vkdt.state.center_x, win_y = vkdt.state.center_y;
int win_w = vkdt.state.center_wd, win_h = vkdt.state.center_ht;
Expand Down

0 comments on commit 00a8e56

Please sign in to comment.