Remove option used only for testing

This commit is contained in:
Kovid Goyal 2026-04-26 13:50:10 +05:30
parent ff560f615e
commit eb6eb37613
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 31 additions and 28 deletions

View file

@ -195,23 +195,16 @@ type drop_status struct {
reading_data bool
is_remote_client bool
root_remote_dir *remote_dir_entry
open_remote_dir *remote_dir_entry
current_remote_entry *remote_dir_entry // used for m=1 only
pending_remote_dirs []*remote_dir_entry
remote_dir_handle_counter int32
root_remote_dir *remote_dir_entry
open_remote_dir *remote_dir_entry
current_remote_entry *remote_dir_entry // used for m=1 only
pending_remote_dirs []*remote_dir_entry
}
func (d *drop_status) next_dir_handle() int32 {
d.remote_dir_handle_counter++
for d.remote_dir_handle_counter == 0 || d.remote_dir_handle_counter == 1 {
d.remote_dir_handle_counter++
}
return d.remote_dir_handle_counter
func (d *drop_status) reset() {
*d = drop_status{cell_x: -1, cell_y: -1}
}
var reset_drop_status = drop_status{cell_x: -1, cell_y: -1}
func (root *remote_dir_entry) close_tree() {
if root.base_dir != nil {
root.base_dir = root.base_dir.unref()
@ -227,7 +220,7 @@ func (dnd *dnd) end_drop() {
dnd.drop_status.root_remote_dir.close_tree()
dnd.drop_status.root_remote_dir = nil
}
dnd.drop_status = reset_drop_status
dnd.drop_status.reset()
dnd.render_screen()
}
@ -246,7 +239,7 @@ func (dnd *dnd) all_mime_data_dropped() (err error) {
}
}
if len(drop_status.uri_list) == 0 {
*drop_status = reset_drop_status
dnd.drop_status.reset()
dnd.data_has_been_dropped = true
dnd.render_screen()
return
@ -335,7 +328,7 @@ func (dnd *dnd) on_drop_move(cell_x, cell_y int, has_more bool, offered_mimes st
}
dnd.drop_status.in_window = cell_x > -1 && cell_y > -1
if !dnd.drop_status.in_window || dnd.drag_started { // disallow self drag and drop
dnd.drop_status = reset_drop_status
dnd.drop_status.reset()
}
mimes_changed := !slices.Equal(prev_status.accepted_mimes, dnd.drop_status.accepted_mimes)
needs_rerender = prev_status.action != dnd.drop_status.action || mimes_changed

View file

@ -130,16 +130,16 @@ func (dnd *dnd) run_loop() (err error) {
if dnd.lp, err = loop.New(); err != nil {
return err
}
dnd.drop_status = reset_drop_status
dnd.drop_status.reset()
dnd.lp.OnInitialize = func() (string, error) {
dnd.lp.AllowLineWrapping(false)
dnd.lp.SetCursorVisible(false)
if dnd.allow_drops {
dnd.lp.StartAcceptingDrops(dnd.opts.MachineId, slices.Collect(maps.Keys(dnd.drop_dests))...)
dnd.lp.StartAcceptingDrops("", slices.Collect(maps.Keys(dnd.drop_dests))...)
}
if dnd.allow_drags {
dnd.lp.StartOfferingDrags(dnd.opts.MachineId)
dnd.lp.StartOfferingDrags("")
}
dnd.lp.SetWindowTitle("Drag and drop")
return "", dnd.render_screen()
@ -199,9 +199,24 @@ func (dnd *dnd) run_loop() (err error) {
switch string(cmd.Payload) {
case "PING":
dnd.send_test_response("PONG")
case "SETUP":
case "SETUP_LOCAL", "SETUP_REMOTE":
dnd.in_test_mode = true
dnd.lp.NoRoundtripToTerminalOnExit()
dnd.drop_status.reset()
dnd.lp.StopAcceptingDrops()
dnd.lp.StopOfferingDrags()
machine_id := ""
if string(cmd.Payload) == "SETUP_REMOTE" {
machine_id = "remote-client-for-test"
}
if dnd.allow_drops {
dnd.lp.StartAcceptingDrops(machine_id, slices.Collect(maps.Keys(dnd.drop_dests))...)
}
if dnd.allow_drags {
dnd.lp.StartOfferingDrags(machine_id)
}
dnd.render_screen()
dnd.send_test_response("SETUP_DONE")
case "GEOMETRY":
dnd.send_test_response(fmt.Sprintf("GEOMETRY:%d:%d:%d:%d:%d:%d:%d:%d", dnd.copy_button_region.left, dnd.copy_button_region.top, dnd.copy_button_region.width, dnd.copy_button_region.height, dnd.move_button_region.left, dnd.move_button_region.top, dnd.move_button_region.width, dnd.move_button_region.height))
case "DROP_MIMES":

View file

@ -33,12 +33,9 @@
type=choices
Allow dropping anywhere, not just on the Copy or Move drop regions. Dropping anywhere will perform
the specified action.
--machine-id
The machine id to use instead of the actual machine id.
'''.format
help_text = '''\
Perform drag and drop operations, even over SSH.

View file

@ -116,19 +116,17 @@ def send_dnd_command_to_kitten(self, payload=b'', as_base64=False, flush=False,
def finish_setup(self, remote_client: bool = False, cli_args = ()):
cmd = [kitten_exe(), 'dnd']
if remote_client:
cmd.append('--machine-id=remote-client-for-test')
cmd += list(cli_args)
self.pty = self.enterContext(PTY(argv=cmd, cwd=self.kitten_wd, rows=25, columns=80, window_id=self.capture.window_id))
self.capture.pty = self.pty
self.pty.callbacks.printbuf = self
self.screen = self.pty.screen
self.pty.wait_till(lambda: bool(self.pty.callbacks.titlebuf))
self.send_dnd_command_to_kitten('SETUP_REMOTE' if remote_client else 'SETUP_LOCAL')
self.wait_for_responses('SETUP_DONE')
self.assertTrue(self.probe_state('drop_wanted'))
self.assertEqual(remote_client, self.probe_state('drop_is_remote_client'))
if self.probe_state('drag_can_offer'):
self.assertEqual(remote_client, self.probe_state('drag_is_remote_client'))
self.send_dnd_command_to_kitten('SETUP')
def get_button_geometry(self, are_present: bool = True):
self.send_dnd_command_to_kitten('GEOMETRY')