build: add libxtst, libpng, tesseract, and leptonica dependencies to Makefile for screenshot and ocr support
This commit is contained in:
+92
-1
@@ -1,16 +1,107 @@
|
||||
/*
|
||||
* retoor <retoor@molodetz.nl>
|
||||
* DWN - Desktop Window Manager
|
||||
* WebSocket API
|
||||
* WebSocket API with event subscription system
|
||||
*/
|
||||
|
||||
#ifndef DWN_API_H
|
||||
#define DWN_API_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
typedef enum {
|
||||
EVENT_WINDOW_CREATED,
|
||||
EVENT_WINDOW_DESTROYED,
|
||||
EVENT_WINDOW_FOCUSED,
|
||||
EVENT_WINDOW_UNFOCUSED,
|
||||
EVENT_WINDOW_MOVED,
|
||||
EVENT_WINDOW_RESIZED,
|
||||
EVENT_WINDOW_MINIMIZED,
|
||||
EVENT_WINDOW_RESTORED,
|
||||
EVENT_WINDOW_MAXIMIZED,
|
||||
EVENT_WINDOW_UNMAXIMIZED,
|
||||
EVENT_WINDOW_FULLSCREEN,
|
||||
EVENT_WINDOW_UNFULLSCREEN,
|
||||
EVENT_WINDOW_FLOATING,
|
||||
EVENT_WINDOW_UNFLOATING,
|
||||
EVENT_WINDOW_TITLE_CHANGED,
|
||||
EVENT_WINDOW_RAISED,
|
||||
EVENT_WINDOW_LOWERED,
|
||||
|
||||
EVENT_WORKSPACE_SWITCHED,
|
||||
EVENT_WORKSPACE_WINDOW_ADDED,
|
||||
EVENT_WORKSPACE_WINDOW_REMOVED,
|
||||
EVENT_WORKSPACE_LAYOUT_CHANGED,
|
||||
EVENT_WORKSPACE_MASTER_RATIO_CHANGED,
|
||||
EVENT_WORKSPACE_MASTER_COUNT_CHANGED,
|
||||
EVENT_WORKSPACE_ARRANGED,
|
||||
|
||||
EVENT_LAYOUT_CHANGED,
|
||||
|
||||
EVENT_KEY_PRESSED,
|
||||
EVENT_KEY_RELEASED,
|
||||
EVENT_SHORTCUT_TRIGGERED,
|
||||
|
||||
EVENT_MOUSE_MOVED,
|
||||
EVENT_MOUSE_BUTTON_PRESSED,
|
||||
EVENT_MOUSE_BUTTON_RELEASED,
|
||||
|
||||
EVENT_DRAG_STARTED,
|
||||
EVENT_DRAG_ENDED,
|
||||
|
||||
EVENT_SHOW_DESKTOP_TOGGLED,
|
||||
|
||||
EVENT_NOTIFICATION_SHOWN,
|
||||
EVENT_NOTIFICATION_CLOSED,
|
||||
|
||||
EVENT_COUNT
|
||||
} ApiEventType;
|
||||
|
||||
void api_init(void);
|
||||
void api_process(void);
|
||||
void api_cleanup(void);
|
||||
void api_handle_json_command(const char *json_str);
|
||||
|
||||
const char *api_event_name(ApiEventType type);
|
||||
|
||||
void api_emit_window_created(Window window, const char *title, const char *class_name, int workspace);
|
||||
void api_emit_window_destroyed(Window window, const char *title, int workspace);
|
||||
void api_emit_window_focused(Window window, const char *title, Window prev_window);
|
||||
void api_emit_window_unfocused(Window window, const char *title);
|
||||
void api_emit_window_moved(Window window, int old_x, int old_y, int new_x, int new_y);
|
||||
void api_emit_window_resized(Window window, int old_w, int old_h, int new_w, int new_h);
|
||||
void api_emit_window_minimized(Window window);
|
||||
void api_emit_window_restored(Window window);
|
||||
void api_emit_window_maximized(Window window, bool maximized);
|
||||
void api_emit_window_fullscreen(Window window, bool fullscreen);
|
||||
void api_emit_window_floating(Window window, bool floating);
|
||||
void api_emit_window_title_changed(Window window, const char *old_title, const char *new_title);
|
||||
void api_emit_window_raised(Window window);
|
||||
void api_emit_window_lowered(Window window);
|
||||
|
||||
void api_emit_workspace_switched(int old_workspace, int new_workspace);
|
||||
void api_emit_workspace_window_added(int workspace, Window window);
|
||||
void api_emit_workspace_window_removed(int workspace, Window window);
|
||||
void api_emit_workspace_layout_changed(int workspace, int old_layout, int new_layout);
|
||||
void api_emit_workspace_master_ratio_changed(int workspace, float old_ratio, float new_ratio);
|
||||
void api_emit_workspace_master_count_changed(int workspace, int old_count, int new_count);
|
||||
void api_emit_workspace_arranged(int workspace, int layout);
|
||||
|
||||
void api_emit_key_pressed(unsigned int keycode, unsigned int keysym, unsigned int modifiers);
|
||||
void api_emit_key_released(unsigned int keycode, unsigned int keysym, unsigned int modifiers);
|
||||
void api_emit_shortcut_triggered(const char *name, const char *description);
|
||||
|
||||
void api_emit_mouse_moved(int x, int y);
|
||||
void api_emit_mouse_button_pressed(int button, int x, int y);
|
||||
void api_emit_mouse_button_released(int button, int x, int y);
|
||||
|
||||
void api_emit_drag_started(Window window, bool is_resize);
|
||||
void api_emit_drag_ended(Window window, bool is_resize);
|
||||
|
||||
void api_emit_show_desktop_toggled(bool shown);
|
||||
|
||||
void api_emit_notification_shown(unsigned int id, const char *summary, const char *body);
|
||||
void api_emit_notification_closed(unsigned int id);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* DWN - Desktop Window Manager
|
||||
* retoor <retoor@molodetz.nl>
|
||||
* OCR text extraction API
|
||||
*/
|
||||
|
||||
#ifndef DWN_OCR_H
|
||||
#define DWN_OCR_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <pthread.h>
|
||||
|
||||
typedef enum {
|
||||
OCR_OK = 0,
|
||||
OCR_ERROR_INVALID_ARG,
|
||||
OCR_ERROR_INIT,
|
||||
OCR_ERROR_IMAGE,
|
||||
OCR_ERROR_NO_MEMORY,
|
||||
OCR_ERROR_NOT_AVAILABLE
|
||||
} OcrStatus;
|
||||
|
||||
typedef enum {
|
||||
OCR_STATE_IDLE,
|
||||
OCR_STATE_PENDING,
|
||||
OCR_STATE_COMPLETED,
|
||||
OCR_STATE_ERROR
|
||||
} OcrState;
|
||||
|
||||
typedef struct {
|
||||
char *text;
|
||||
size_t length;
|
||||
float confidence;
|
||||
} OcrResult;
|
||||
|
||||
typedef struct OcrRequest {
|
||||
unsigned char *png_data;
|
||||
size_t png_size;
|
||||
char language[16];
|
||||
|
||||
OcrResult result;
|
||||
OcrStatus status;
|
||||
OcrState state;
|
||||
|
||||
void (*callback)(struct OcrRequest *req);
|
||||
void *user_data;
|
||||
|
||||
pthread_t thread;
|
||||
struct OcrRequest *next;
|
||||
} OcrRequest;
|
||||
|
||||
bool ocr_init(void);
|
||||
void ocr_cleanup(void);
|
||||
bool ocr_is_available(void);
|
||||
|
||||
OcrStatus ocr_extract_from_png(const unsigned char *png_data, size_t size,
|
||||
const char *language, OcrResult *result);
|
||||
|
||||
OcrRequest *ocr_extract_async(const unsigned char *png_data, size_t size,
|
||||
const char *language,
|
||||
void (*callback)(OcrRequest *));
|
||||
|
||||
void ocr_process_pending(void);
|
||||
void ocr_cancel(OcrRequest *req);
|
||||
|
||||
void ocr_result_free(OcrResult *result);
|
||||
|
||||
const char *ocr_status_string(OcrStatus status);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* DWN - Desktop Window Manager
|
||||
* retoor <retoor@molodetz.nl>
|
||||
* Screenshot capture API
|
||||
*/
|
||||
|
||||
#ifndef DWN_SCREENSHOT_H
|
||||
#define DWN_SCREENSHOT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <pthread.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
typedef enum {
|
||||
SCREENSHOT_OK = 0,
|
||||
SCREENSHOT_ERROR_INVALID_ARG,
|
||||
SCREENSHOT_ERROR_X11,
|
||||
SCREENSHOT_ERROR_PNG,
|
||||
SCREENSHOT_ERROR_NO_MEMORY,
|
||||
SCREENSHOT_ERROR_WINDOW_NOT_FOUND
|
||||
} ScreenshotStatus;
|
||||
|
||||
typedef enum {
|
||||
SCREENSHOT_STATE_IDLE,
|
||||
SCREENSHOT_STATE_PENDING,
|
||||
SCREENSHOT_STATE_COMPLETED,
|
||||
SCREENSHOT_STATE_ERROR
|
||||
} ScreenshotState;
|
||||
|
||||
typedef enum {
|
||||
SCREENSHOT_MODE_FULLSCREEN,
|
||||
SCREENSHOT_MODE_WINDOW,
|
||||
SCREENSHOT_MODE_ACTIVE,
|
||||
SCREENSHOT_MODE_AREA
|
||||
} ScreenshotMode;
|
||||
|
||||
typedef struct {
|
||||
unsigned char *data;
|
||||
size_t size;
|
||||
int width;
|
||||
int height;
|
||||
} ScreenshotResult;
|
||||
|
||||
typedef struct ScreenshotRequest {
|
||||
ScreenshotMode mode;
|
||||
Window window;
|
||||
int x, y, width, height;
|
||||
|
||||
ScreenshotResult result;
|
||||
ScreenshotStatus status;
|
||||
ScreenshotState state;
|
||||
|
||||
void (*callback)(struct ScreenshotRequest *req);
|
||||
void *user_data;
|
||||
|
||||
pthread_t thread;
|
||||
struct ScreenshotRequest *next;
|
||||
} ScreenshotRequest;
|
||||
|
||||
bool screenshot_init(void);
|
||||
void screenshot_cleanup(void);
|
||||
|
||||
ScreenshotStatus screenshot_capture_fullscreen(ScreenshotResult *result);
|
||||
ScreenshotStatus screenshot_capture_window(Window window, ScreenshotResult *result);
|
||||
ScreenshotStatus screenshot_capture_active(ScreenshotResult *result);
|
||||
ScreenshotStatus screenshot_capture_area(int x, int y, int width, int height, ScreenshotResult *result);
|
||||
|
||||
ScreenshotRequest *screenshot_capture_async(ScreenshotMode mode,
|
||||
void (*callback)(ScreenshotRequest *));
|
||||
ScreenshotRequest *screenshot_capture_window_async(Window window,
|
||||
void (*callback)(ScreenshotRequest *));
|
||||
ScreenshotRequest *screenshot_capture_area_async(int x, int y, int w, int h,
|
||||
void (*callback)(ScreenshotRequest *));
|
||||
|
||||
void screenshot_process_pending(void);
|
||||
void screenshot_cancel(ScreenshotRequest *req);
|
||||
|
||||
char *screenshot_to_base64(const ScreenshotResult *result, size_t *out_len);
|
||||
void screenshot_result_free(ScreenshotResult *result);
|
||||
|
||||
const char *screenshot_status_string(ScreenshotStatus status);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user