Skip to content

Commit

Permalink
finish constifying the packet types
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jul 2, 2024
1 parent 89070bb commit bbf2dfb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
30 changes: 15 additions & 15 deletions html5/js/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ class XpraClient {
this.desktop_width = this.container.clientWidth;
this.desktop_height = this.container.clientHeight;
const newsize = [this.desktop_width, this.desktop_height];
const packet = ["desktop_size", newsize[0], newsize[1], this._get_screen_sizes()];
const packet = [PACKET_TYPES.desktop_size, newsize[0], newsize[1], this._get_screen_sizes()];
this.send(packet);
// call the screen_resized function on all open windows
for (const index in this.id_to_window) {
Expand Down Expand Up @@ -1142,10 +1142,10 @@ class XpraClient {

if (this.topwindow != undefined) {
const wid = this.topwindow;
let packet = ["key-action", wid, keyname, pressed, modifiers, keyval, keystring, keycode, group];
let packet = [PACKET_TYPES.key_action, wid, keyname, pressed, modifiers, keyval, keystring, keycode, group];
this.key_packets.push(packet);
if (unpress_now) {
packet = ["key-action", wid, keyname, false, modifiers, keyval, keystring, keycode, group];
packet = [PACKET_TYPES.key_action, wid, keyname, false, modifiers, keyval, keystring, keycode, group];
this.key_packets.push(packet);
}

Expand Down Expand Up @@ -3088,7 +3088,7 @@ class XpraClient {
this.id_to_window[wid] = win;
if (!override_redirect) {
const geom = win.get_internal_geometry();
this.send(["map-window", wid, geom.x, geom.y, geom.w, geom.h, win.client_properties]);
this.send([PACKET_TYPES.map_window, wid, geom.x, geom.y, geom.w, geom.h, win.client_properties]);
this.set_focus(win);
}
}
Expand Down Expand Up @@ -3345,7 +3345,7 @@ class XpraClient {
});
const reason = 2; //closed by the user - best guess...
notification.addEventListener("close", () =>
context.send(["notification-close", nid, reason, ""])
context.send([PACKET_TYPES.notification_close, nid, reason, ""])
);
notification.addEventListener("click", () =>
context.log("user clicked on notification", nid)
Expand All @@ -3370,10 +3370,10 @@ class XpraClient {
if (window.doNotification) {
window.doNotification("info", nid, summary, body, expire_timeout, icon, actions, hints,
function (nid, action_id) {
context.send(["notification-action", nid, action_id]);
context.send([PACKET_TYPES.notification_action, nid, action_id]);
},
function (nid, reason, text) {
context.send(["notification-close", nid, reason, text || ""]);
context.send([PACKET_TYPES.notification_close, nid, reason, text || ""]);
}
);
}
Expand Down Expand Up @@ -3515,7 +3515,7 @@ class XpraClient {
if (!protocol) {
return;
}
const packet = ["damage-sequence", packet_sequence, wid, width, height, decode_time, message];
const packet = [PACKET_TYPES.damage_sequence, packet_sequence, wid, width, height, decode_time, message];
if (decode_time < 0) {
this.cwarn("decode error packet:", packet);
}
Expand Down Expand Up @@ -4029,7 +4029,7 @@ class XpraClient {
let packet;
packet = data
? [
"clipboard-token",
PACKET_TYPES.clipboard_token,
"CLIPBOARD",
actual_data_format,
UTF8_STRING,
Expand All @@ -4042,7 +4042,7 @@ class XpraClient {
synchronous,
]
: [
"clipboard-token",
PACKET_TYPES.clipboard_token,
"CLIPBOARD",
[],
"",
Expand Down Expand Up @@ -4257,7 +4257,7 @@ class XpraClient {
}

send_clipboard_none(request_id, selection) {
const packet = ["clipboard-contents-none", request_id, selection];
const packet = [PACKET_TYPES.clipboard_contents_none, request_id, selection];
this.debug("clipboard", "sending clipboard-contents-none");
this.send(packet);
}
Expand All @@ -4267,7 +4267,7 @@ class XpraClient {
this.send_clipboard_none(request_id, selection);
return;
}
const packet = ["clipboard-contents", request_id, selection, datatype || UTF8_STRING, 8, "bytes", clipboard_buffer];
const packet = [PACKET_TYPES.clipboard_contents, request_id, selection, datatype || UTF8_STRING, 8, "bytes", clipboard_buffer];
this.debug("clipboard", "send_clipboard_string: packet=", packet);
this.send(packet);
}
Expand All @@ -4277,7 +4277,7 @@ class XpraClient {
this.send_clipboard_none(request_id, selection);
return;
}
const packet = ["clipboard-contents", request_id, selection, datatype, dformat || 8, encoding || "bytes", clipboard_buffer];
const packet = [PACKET_TYPES.clipboard_contents, request_id, selection, datatype, dformat || 8, encoding || "bytes", clipboard_buffer];
this.send(packet);
}

Expand Down Expand Up @@ -4643,7 +4643,7 @@ class XpraClient {
//send everything now:
this.debug("file", "sending full file:", size, "bytes, chunk size", chunk_size);
}
const packet = ["send-file", filename, mimetype, false, this.remote_open_files, size, cdata, options];
const packet = [PACKET_TYPES.send_file, filename, mimetype, false, this.remote_open_files, size, cdata, options];
this.send(packet);
}

Expand Down Expand Up @@ -4730,7 +4730,7 @@ class XpraClient {
}

start_command(name, command, ignore) {
const packet = ["start-command", name, command, ignore];
const packet = [PACKET_TYPES.start_command, name, command, ignore];
this.send(packet);
}

Expand Down
9 changes: 9 additions & 0 deletions html5/js/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ const PACKET_TYPES = {
challenge: "challenge",
clipboard_request: "clipboard-request",
clipboard_token: "clipboard-token",
clipboard_contents_none: "clipboard-contents-none",
clipboard_contents: "clipboard-contents",
close: "close",
close_window: "close-window",
configure_override_redirect: "configure-override-redirect",
configure_window: "configure-window",
connection_data: "connection-data",
cursor: "cursor",
damage_sequence: "damage-sequence",
desktop_size: "desktop_size",
disconnect: "disconnect",
draw: "draw",
Expand All @@ -86,12 +89,16 @@ const PACKET_TYPES = {
info_request: "info-request",
info_response: "info-response",
initiate_moveresize: "initiate-moveresize",
key_action: "key-action",
layout_changed: "layout-changed",
logging: "logging",
lost_window: "lost-window",
map_window: "map-window",
new_override_redirect: "new-override-redirect",
new_tray: "new-tray",
new_window: "new-window",
notification_action: "notification-action",
notification_close: "notification-close",
notify_close: "notify_close",
notify_show: "notify_show",
open: "open",
Expand All @@ -109,7 +116,9 @@ const PACKET_TYPES = {
sound_control: "sound-control",
sound_data: "sound-data",
startup_complete: "startup-complete",
start_command: "start-command",
suspend: "suspend",
unmap_window: "unmap-window",
wheel_motion: "wheel-motion",
window_icon: "window-icon",
window_metadata: "window-metadata",
Expand Down
4 changes: 2 additions & 2 deletions html5/js/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,13 @@ class XpraWindow {
const geom = this.get_internal_geometry();
this.set_minimized(!this.minimized);
if (this.minimized) {
this.client.send(["unmap-window", this.wid, true]);
this.client.send([PACKET_TYPES.unmap_window, this.wid, true]);
this.stacking_layer = 0;
if (this.client.focus == this.wid) {
this.client.auto_focus();
}
} else {
this.client.send(["map-window", this.wid, geom.x, geom.y, geom.w, geom.h, this.client_properties]);
this.client.send([PACKET_TYPES.map_window, this.wid, geom.x, geom.y, geom.w, geom.h, this.client_properties]);
//force focus switch:
this.client.focus = -1;
this.client.set_focus(this);
Expand Down

0 comments on commit bbf2dfb

Please sign in to comment.