Skip to content

Commit

Permalink
Make it work on mobile with autocompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlent committed May 28, 2023
1 parent 07b5445 commit 4b79ba6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
21 changes: 18 additions & 3 deletions cozycast-server/npm-website/src/private/js/MobileRemoteControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ export const MobileRemoteControls = ({ lastRemotePosition }) => {
});
}

const handleCompositionend = (e) => {
if (!remoteInfo.value.remote) { return }
let key = e.data;
e.target.value += key;
if (key.length > 1) {
e.preventDefault();
sendMessage({
action: 'textinput',
text: key
});
return;
}
}

const handleInput = (e) => {
if (!remoteInfo.value.remote) { return }
let key = null;
Expand All @@ -47,8 +61,8 @@ export const MobileRemoteControls = ({ lastRemotePosition }) => {
if (key.length > 1) {
e.preventDefault();
sendMessage({
action: 'paste',
clipboard: key
action: 'textinput',
text: key
});
return;
}
Expand Down Expand Up @@ -117,6 +131,7 @@ export const MobileRemoteControls = ({ lastRemotePosition }) => {
<div className="touchpad-controls">
<div class="textarea-wrapper">
<textarea autocomplete="off" autocorrect="off" spellcheck="false" autocapitalize="off" className="keyboard-input"
onCompositionend={handleCompositionend}
onKeyDown={handleKeyDown}
onBeforeInput={handleInput}
onTouchStart={handleTextAreaClick}
Expand All @@ -137,4 +152,4 @@ export const MobileRemoteControls = ({ lastRemotePosition }) => {
</button>
</div>
);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ class NextRestartAvailable {
String time
}

class TextinputEvent {
String action = "textinput"
String text
}

class PasteEvent {
String action = "paste"
String clipboard
Expand Down Expand Up @@ -987,12 +992,19 @@ class WebsocketRoomService {
}
}

private void scroll(Room room, WebSocketSession session, Map jsonMessage , String username) {
private void scroll(Room room, WebSocketSession session, Map jsonMessage, String username) {
if(username == room.remote) {
sendMessage(room.worker?.websocket, new ScrollEvent(direction: jsonMessage.direction))
}
}

private void textinput(Room room, WebSocketSession session, Map jsonMessage, String username) {
if(username == room.remote) {
log.info jsonMessage.toString()
sendMessage(room.worker?.websocket, new TextinputEvent(text: jsonMessage.text));
}
}

private void paste(Room room, WebSocketSession session, Map jsonMessage, String username) {
if(username == room.remote) {
log.info jsonMessage.toString()
Expand Down Expand Up @@ -1459,6 +1471,9 @@ class WebsocketRoomService {
case "mousedown":
mousedown(currentRoom, session, jsonMessage, username)
break;
case "textinput":
textinput(currentRoom, session, jsonMessage, username)
break;
case "paste":
paste(currentRoom, session, jsonMessage, username)
break;
Expand Down
10 changes: 10 additions & 0 deletions cozycast-worker/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int xdo_move_mouse(const xdo_t *xdo, int x, int y, int screen);
int xdo_click_window(const xdo_t *xdo, Window window, int button);
int xdo_mouse_down(const xdo_t *xdo, Window window, int button);
int xdo_mouse_up(const xdo_t *xdo, Window window, int button);
int xdo_enter_text_window(const xdo_t *xdo, Window window, const char *string, useconds_t delay);
int xdo_send_keysequence_window(const xdo_t *xdo, Window window,
const char *keysequence, useconds_t delay);
int xdo_send_keysequence_window_up(const xdo_t *xdo, Window window,
Expand Down Expand Up @@ -249,6 +250,10 @@ function worker.mouse_down(mouseX, mouseY, button)
end
end

function worker.textinput(text)
libxdo.xdo_enter_text_window(xdo, 0, text, 0);
end

function worker.clipboard_write(text)
local xclip = io.popen("xclip -selection clipboard", 'w')
xclip:write(text or "")
Expand Down Expand Up @@ -338,6 +343,11 @@ function onmessage(ws, data)
return true
end

if data.action == "textinput" then
worker.textinput(data.text)
return true
end

if data.action == "paste" then
worker.clipboard_write(data.clipboard)
return true
Expand Down

0 comments on commit 4b79ba6

Please sign in to comment.