Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions controller-bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Build directory
build/

# Objetos
*.o
*.d

# Bibliotecas
*.a
*.so

# Binário gerado
controller-bridge

# Core dumps
core
core.*

# Editor
.vscode/
.idea/

# Sistema
.DS_Store
21 changes: 21 additions & 0 deletions controller-bridge/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Alberto Biason and Steam Media Pack contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 48 additions & 0 deletions controller-bridge/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
CC := gcc

TARGET := controller-bridge

SRC_DIR := src
INC_DIR := include
BUILD_DIR := build

SOURCES := $(wildcard $(SRC_DIR)/*.c)
OBJECTS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SOURCES))
DEPENDENCIES := $(OBJECTS:.o=.d)

SDL2_CFLAGS := $(shell pkg-config --cflags sdl2)
SDL2_LIBS := $(shell pkg-config --libs sdl2)

CPPFLAGS := -I$(INC_DIR) $(SDL2_CFLAGS)
CFLAGS := -std=c11 -O2 -Wall -Wextra -Wpedantic
LDFLAGS :=
LDLIBS := $(SDL2_LIBS) -lm

.PHONY: all clean debug release install uninstall

all: $(TARGET)

$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(LDLIBS)

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(BUILD_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@

debug: CFLAGS := -std=c11 -O0 -g3 -Wall -Wextra -Wpedantic
debug: clean all

release: CFLAGS := -std=c11 -O2 -DNDEBUG -Wall -Wextra -Wpedantic
release: clean all

install: $(TARGET)
install -Dm755 $(TARGET) \
$(DESTDIR)/usr/local/bin/$(TARGET)

uninstall:
rm -f $(DESTDIR)/usr/local/bin/$(TARGET)

clean:
rm -rf $(BUILD_DIR) $(TARGET)

-include $(DEPENDENCIES)
35 changes: 35 additions & 0 deletions controller-bridge/README.pt-BR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Steam Media Pack Controller Bridge

## Objetivo

O Controller Bridge é um componente experimental do Steam Media Pack responsável por criar um mouse virtual utilizando `uinput` e controlar esse mouse através de um controle compatível com SDL2.

A motivação deste projeto é eliminar a dependência do Steam Input para navegação nas plataformas de streaming, proporcionando um comportamento consistente entre serviços como Netflix, Disney+, Max, Prime Video, Spotify e YouTube.

## Funcionalidades previstas

- Mouse virtual via Linux uinput
- Compatibilidade com SDL2 GameController API
- Reconexão automática de controles
- Movimento do cursor pelo analógico direito
- Clique esquerdo, direito e botão do meio
- Rolagem utilizando os gatilhos
- Execução em segundo plano como serviço de usuário (systemd)

## Status

**Experimental**

Este componente ainda está em desenvolvimento e não faz parte da versão estável do Steam Media Pack.

## Compilação

```bash
make
```

## Limpeza

```bash
make clean
```
9 changes: 9 additions & 0 deletions controller-bridge/controller.conf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cursor.deadzone=8000
cursor.max_speed=20
cursor.exponent=2.2
cursor.sensitivity=1.0
cursor.smoothing=0.75

scroll.initial_delay=250
scroll.repeat_interval=75
scroll.step=1
61 changes: 61 additions & 0 deletions controller-bridge/include/cli.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef CLI_H
#define CLI_H

#include <stdbool.h>

/*
* Opções obtidas a partir da linha de comando.
*/
typedef struct
{
/*
* Caminho do arquivo de configuração.
*
* Quando NULL, o programa utilizará
* CONFIG_DEFAULT_PATH.
*/
const char *config_path;

/*
* Exibe a ajuda.
*/
bool show_help;

/*
* Exibe a versão.
*/
bool show_version;

} CliOptions;

/*
* Inicializa a estrutura com os valores padrão.
*/
void cli_init(
CliOptions *options);

/*
* Processa os argumentos da linha de comando.
*
* Retorna:
*
* true -> argumentos válidos.
* false -> argumento inválido.
*/
bool cli_parse(
CliOptions *options,
int argc,
char **argv);

/*
* Exibe a ajuda do programa.
*/
void cli_print_help(
const char *program_name);

/*
* Exibe a versão do programa.
*/
void cli_print_version(void);

#endif
10 changes: 10 additions & 0 deletions controller-bridge/include/clock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef SMP_CLOCK_H
#define SMP_CLOCK_H

#include <stdint.h>

uint64_t clock_now_ms(void);

void clock_sleep_ms(uint32_t ms);

#endif /* SMP_CLOCK_H */
22 changes: 22 additions & 0 deletions controller-bridge/include/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef SMP_CONFIG_H
#define SMP_CONFIG_H

typedef struct
{
int cursor_deadzone;
int cursor_max_speed;

float cursor_exponent;
float cursor_sensitivity;
float cursor_smoothing;

unsigned int scroll_initial_delay_ms;
unsigned int scroll_repeat_interval_ms;
int scroll_step;
} ControllerConfig;

extern ControllerConfig g_config;

void config_set_defaults(void);

#endif /* SMP_CONFIG_H */
36 changes: 36 additions & 0 deletions controller-bridge/include/config_parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef CONFIG_PARSER_H
#define CONFIG_PARSER_H

#include <stdbool.h>

/*
* Arquivo de configuração padrão.
*/
#define CONFIG_DEFAULT_PATH "controller.conf"

/*
* Tamanho máximo de uma linha do arquivo
* de configuração.
*/
#define CONFIG_MAX_LINE_LENGTH 256

/*
* Carrega as configurações do arquivo informado.
*
* As configurações válidas são aplicadas diretamente
* à estrutura global g_config.
*
* Retorna:
*
* true:
* O arquivo foi aberto e processado.
*
* false:
* O caminho é inválido ou o arquivo não pôde ser aberto.
*
* Linhas inválidas são ignoradas e registradas no log,
* mantendo os valores atuais de g_config.
*/
bool config_load(const char *path);

#endif
22 changes: 22 additions & 0 deletions controller-bridge/include/controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef SMP_CONTROLLER_H
#define SMP_CONTROLLER_H

#include "cursor.h"

#include <SDL2/SDL.h>
#include <stdbool.h>
#include <stdint.h>

#include "input.h"

SDL_GameController *controller_open_first(void);

void controller_close(SDL_GameController *);

bool controller_is_connected(SDL_GameController *);

void controller_poll(
SDL_GameController *,
InputState *);

#endif
17 changes: 17 additions & 0 deletions controller-bridge/include/cursor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef SMP_CURSOR_H
#define SMP_CURSOR_H

#include <SDL2/SDL.h>

typedef struct
{
int delta_x;
int delta_y;
} CursorState;

void cursor_update(
Sint16 axis_x,
Sint16 axis_y,
CursorState *state);

#endif
32 changes: 32 additions & 0 deletions controller-bridge/include/input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef SMP_INPUT_H
#define SMP_INPUT_H

#include <stdint.h>

#include "cursor.h"

typedef enum
{
INPUT_NONE = 0,

INPUT_LEFT_CLICK = 1 << 0,
INPUT_RIGHT_CLICK = 1 << 1,
INPUT_MIDDLE_CLICK = 1 << 2,

INPUT_SCROLL_UP = 1 << 3,
INPUT_SCROLL_DOWN = 1 << 4

} InputActions;

typedef struct
{
uint32_t actions;
} ButtonState;

typedef struct
{
CursorState cursor;
ButtonState buttons;
} InputState;

#endif /* SMP_INPUT_H */
Loading
Loading