library: window cancelreposition API

This commit is contained in:
Adam
2024-10-24 16:25:58 +01:00
parent eb1c10c2a7
commit faacac811f
3 changed files with 29 additions and 2 deletions

View File

@@ -45,6 +45,7 @@ enum BoltIPCMessageTypeToClient {
IPC_MSG_EXTERNALBROWSERMESSAGE,
IPC_MSG_OSRBROWSERMESSAGE,
IPC_MSG_OSRSTARTREPOSITION,
IPC_MSG_OSRCANCELREPOSITION,
IPC_MSG_BROWSERCLOSEREQUEST,
IPC_MSG_OSRCLOSEREQUEST,
};
@@ -157,6 +158,11 @@ struct BoltIPCOsrStartRepositionHeader {
int8_t vertical; // -1 for top edge, 1 for bottom edge
};
/// Header for BoltMessageTypeToClient::IPC_MSG_OSRCANCELREPOSITION
struct BoltIPCOsrCancelRepositionHeader {
uint64_t window_id;
};
/// Header for BoltMessageTypeToClient::IPC_MSG_BROWSERCLOSEREQUEST
struct BoltIPCBrowserCloseRequestHeader {
uint64_t window_id;

View File

@@ -876,10 +876,15 @@ static void handle_ipc_OSRBROWSERMESSAGE(struct BoltIPCBrowserMessageHeader* hea
static void handle_ipc_OSRSTARTREPOSITION(struct BoltIPCOsrStartRepositionHeader* header, struct EmbeddedWindow* window) {
window->reposition_mode = true;
window->reposition_threshold = false;
window->reposition_w = header->horizontal;
window->reposition_h = header->vertical;
}
static void handle_ipc_OSRCANCELREPOSITION(struct BoltIPCOsrCancelRepositionHeader* header, struct EmbeddedWindow* window) {
window->reposition_mode = false;
}
static void handle_ipc_BROWSERCLOSEREQUEST(struct BoltIPCBrowserCloseRequestHeader* header, struct ExternalBrowser* browser) {
handle_close_request(browser->plugin->state, header->window_id);
}
@@ -902,6 +907,7 @@ void _bolt_plugin_handle_messages() {
IPCCASEBROWSERTAIL(EXTERNALBROWSERMESSAGE, BrowserMessage)
IPCCASEWINDOWTAIL(OSRBROWSERMESSAGE, BrowserMessage)
IPCCASEWINDOW(OSRSTARTREPOSITION, OsrStartReposition)
IPCCASEWINDOW(OSRCANCELREPOSITION, OsrCancelReposition)
IPCCASEBROWSER(BROWSERCLOSEREQUEST, BrowserCloseRequest)
IPCCASEWINDOW(OSRCLOSEREQUEST, OsrCloseRequest)
default:
@@ -1072,13 +1078,14 @@ uint8_t _bolt_plugin_add(const char* path, struct Plugin* plugin) {
PUSHSTRING(plugin->state, WINDOW_META_REGISTRYNAME);
lua_newtable(plugin->state);
PUSHSTRING(plugin->state, "__index");
lua_createtable(plugin->state, 0, 11);
lua_createtable(plugin->state, 0, 12);
API_ADD_SUB(plugin->state, close, window)
API_ADD_SUB(plugin->state, id, window)
API_ADD_SUB(plugin->state, size, window)
API_ADD_SUB(plugin->state, clear, window)
API_ADD_SUB(plugin->state, subimage, window)
API_ADD_SUB(plugin->state, startreposition, window)
API_ADD_SUB(plugin->state, cancelreposition, window)
API_ADD_SUB(plugin->state, onreposition, window)
API_ADD_SUB(plugin->state, onmousemotion, window)
API_ADD_SUB(plugin->state, onmousebutton, window)
@@ -1091,9 +1098,11 @@ uint8_t _bolt_plugin_add(const char* path, struct Plugin* plugin) {
PUSHSTRING(plugin->state, BROWSER_META_REGISTRYNAME);
lua_newtable(plugin->state);
PUSHSTRING(plugin->state, "__index");
lua_createtable(plugin->state, 0, 3);
lua_createtable(plugin->state, 0, 6);
API_ADD_SUB(plugin->state, close, browser)
API_ADD_SUB(plugin->state, sendmessage, browser)
API_ADD_SUB(plugin->state, startreposition, window)
API_ADD_SUB(plugin->state, cancelreposition, window)
API_ADD_SUB(plugin->state, oncloserequest, browser)
API_ADD_SUB(plugin->state, onmessage, browser)
lua_settable(plugin->state, -3);
@@ -1954,6 +1963,13 @@ static int api_window_startreposition(lua_State* state) {
return 0;
}
static int api_window_cancelreposition(lua_State* state) {
_bolt_check_argc(state, 3, "window_cancelreposition");
struct EmbeddedWindow* window = lua_touserdata(state, 1);
window->reposition_mode = false;
return 0;
}
static int api_render3d_vertexcount(lua_State* state) {
_bolt_check_argc(state, 1, "render3d_vertexcount");
const struct Render3D* render = lua_touserdata(state, 1);

View File

@@ -478,6 +478,11 @@ static int api_window_subimage(lua_State*);
/// bottom edge. Finally, if both are zero, the window will be moved instead of resized.
static int api_window_startreposition(lua_State*);
/// [-1, +0, -]
/// Cancels repositioning for this window. If the window is in the process of being repositioned by
/// the user dragging it, that will be cancelled and no repositioning will take place.
static int api_window_cancelreposition(lua_State*);
/// [-2, +0, -]
/// Sets an event handler for this window for reposition events. If the value is a function, it
/// will be called with one parameter, that being a reposition event object. If the value is not a