Don't display cursor when using gamepad

This commit is contained in:
loki 2019-12-25 20:57:23 +01:00
parent c11872f0f5
commit c3cba2bdad
7 changed files with 25 additions and 20 deletions

@ -115,12 +115,16 @@ void print(void *input) {
} }
void passthrough(platf::input_t &input, PNV_MOUSE_MOVE_PACKET packet) { void passthrough(platf::input_t &input, PNV_MOUSE_MOVE_PACKET packet) {
display_cursor = true;
platf::move_mouse(input, util::endian::big(packet->deltaX), util::endian::big(packet->deltaY)); platf::move_mouse(input, util::endian::big(packet->deltaX), util::endian::big(packet->deltaY));
} }
void passthrough(platf::input_t &input, PNV_MOUSE_BUTTON_PACKET packet) { void passthrough(platf::input_t &input, PNV_MOUSE_BUTTON_PACKET packet) {
auto constexpr BUTTON_RELEASED = 0x09; auto constexpr BUTTON_RELEASED = 0x09;
display_cursor = true;
platf::button_mouse(input, util::endian::big(packet->button), packet->action == BUTTON_RELEASED); platf::button_mouse(input, util::endian::big(packet->button), packet->action == BUTTON_RELEASED);
} }
@ -131,10 +135,14 @@ void passthrough(platf::input_t &input, PNV_KEYBOARD_PACKET packet) {
} }
void passthrough(platf::input_t &input, PNV_SCROLL_PACKET packet) { void passthrough(platf::input_t &input, PNV_SCROLL_PACKET packet) {
display_cursor = true;
platf::scroll(input, util::endian::big(packet->scrollAmt1)); platf::scroll(input, util::endian::big(packet->scrollAmt1));
} }
void passthrough(std::shared_ptr<input_t> &input, PNV_MULTI_CONTROLLER_PACKET packet) { void passthrough(std::shared_ptr<input_t> &input, PNV_MULTI_CONTROLLER_PACKET packet) {
display_cursor = false;
std::uint16_t bf; std::uint16_t bf;
std::memcpy(&bf, &packet->buttonFlags, sizeof(std::uint16_t)); std::memcpy(&bf, &packet->buttonFlags, sizeof(std::uint16_t));

@ -19,6 +19,8 @@ extern "C" {
using namespace std::literals; using namespace std::literals;
util::ThreadPool task_pool; util::ThreadPool task_pool;
bool display_cursor;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if(argc > 1) { if(argc > 1) {
if(!std::filesystem::exists(argv[1])) { if(!std::filesystem::exists(argv[1])) {

@ -8,5 +8,6 @@
#include "thread_pool.h" #include "thread_pool.h"
extern util::ThreadPool task_pool; extern util::ThreadPool task_pool;
extern bool display_cursor;
#endif //SUNSHINE_MAIN_H #endif //SUNSHINE_MAIN_H

@ -22,16 +22,6 @@ using mic_t = util::safe_ptr<void, freeMic>;
using audio_t = util::safe_ptr<void, freeAudio>; using audio_t = util::safe_ptr<void, freeAudio>;
using input_t = util::safe_ptr<void, freeInput>; using input_t = util::safe_ptr<void, freeInput>;
struct gamepad_state_t {
std::uint16_t buttonFlags;
std::uint8_t lt;
std::uint8_t rt;
std::int16_t lsX;
std::int16_t lsY;
std::int16_t rsX;
std::int16_t rsY;
};
std::string get_local_ip(); std::string get_local_ip();
void terminate_process(std::uint64_t handle); void terminate_process(std::uint64_t handle);
@ -40,7 +30,7 @@ mic_t microphone();
audio_t audio(mic_t &mic, std::uint32_t sample_size); audio_t audio(mic_t &mic, std::uint32_t sample_size);
display_t display(); display_t display();
img_t snapshot(display_t &display); img_t snapshot(display_t &display_void, bool cursor);
int32_t img_width(img_t &); int32_t img_width(img_t &);
int32_t img_height(img_t &); int32_t img_height(img_t &);

@ -115,7 +115,7 @@ display_t display() {
return display_t { new display_attr_t {} }; return display_t { new display_attr_t {} };
} }
img_t snapshot(display_t &display_void) { img_t snapshot(display_t &display_void, bool cursor) {
auto &display = *((display_attr_t*)display_void.get()); auto &display = *((display_attr_t*)display_void.get());
display.refresh(); display.refresh();
@ -127,6 +127,10 @@ img_t snapshot(display_t &display_void) {
AllPlanes, ZPixmap) AllPlanes, ZPixmap)
}; };
if(!cursor) {
return img_t { img };
}
XFixesCursorImage *overlay = XFixesGetCursorImage(display.display); XFixesCursorImage *overlay = XFixesGetCursorImage(display.display);
overlay->x -= overlay->xhot; overlay->x -= overlay->xhot;
overlay->y -= overlay->yhot; overlay->y -= overlay->yhot;

@ -26,11 +26,9 @@ struct input_raw_t {
uinput_t mouse_input; uinput_t mouse_input;
display_t display; display_t display;
gamepad_state_t gamepad_state;
}; };
//TODO: Use libevdev for keyboard and mouse, then any mention of X11 can be removed from linux_input.cpp //TODO: Use libevdev for keyboard and mouse, then any mention of X11 can be removed from linux_evdev.cpp
struct display_attr_t { struct display_attr_t {
display_attr_t() : display { XOpenDisplay(nullptr) }, window { DefaultRootWindow(display) }, attr {} { display_attr_t() : display { XOpenDisplay(nullptr) }, window { DefaultRootWindow(display) }, attr {} {
XGetWindowAttributes(display, window, &attr); XGetWindowAttributes(display, window, &attr);

@ -6,15 +6,15 @@
#include <fstream> #include <fstream>
#include <thread> #include <thread>
#include "platform/common.h"
extern "C" { extern "C" {
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libswscale/swscale.h> #include <libswscale/swscale.h>
} }
#include "platform/common.h"
#include "config.h" #include "config.h"
#include "video.h" #include "video.h"
#include "main.h"
namespace video { namespace video {
using namespace std::literals; using namespace std::literals;
@ -121,9 +121,11 @@ void encodeThread(
ctx->rc_min_rate = config.bitrate; ctx->rc_min_rate = config.bitrate;
} }
else if(config::video.crf != 0) { else if(config::video.crf != 0) {
ctx->gop_size = config::video.gop_size;
av_dict_set_int(&options, "crf", config::video.crf, 0); av_dict_set_int(&options, "crf", config::video.crf, 0);
} }
else { else {
ctx->gop_size = config::video.gop_size;
av_dict_set_int(&options, "qp", config::video.qp, 0); av_dict_set_int(&options, "qp", config::video.qp, 0);
} }
@ -169,8 +171,6 @@ void encodeThread(
TUPLE_2D_REF(start, end, *event); TUPLE_2D_REF(start, end, *event);
frame = start; frame = start;
// For some reason, the encoder does not always accept the key_frame when using "end + 1"
key_frame = end + 2; key_frame = end + 2;
} }
else if(frame == key_frame) { else if(frame == key_frame) {
@ -184,6 +184,8 @@ void encodeThread(
} }
void capture_display(packet_queue_t packets, idr_event_t idr_events, config_t config) { void capture_display(packet_queue_t packets, idr_event_t idr_events, config_t config) {
display_cursor = true;
int framerate = config.framerate; int framerate = config.framerate;
img_event_t images {new img_event_t::element_type }; img_event_t images {new img_event_t::element_type };
@ -195,7 +197,7 @@ void capture_display(packet_queue_t packets, idr_event_t idr_events, config_t co
auto time_span = std::chrono::floor<std::chrono::nanoseconds>(1s) / framerate; auto time_span = std::chrono::floor<std::chrono::nanoseconds>(1s) / framerate;
while(packets->running()) { while(packets->running()) {
auto next_snapshot = std::chrono::steady_clock::now() + time_span; auto next_snapshot = std::chrono::steady_clock::now() + time_span;
auto img = platf::snapshot(disp); auto img = platf::snapshot(disp, display_cursor);
images->raise(std::move(img)); images->raise(std::move(img));
img.reset(); img.reset();