Tk Source Code

Artifact [131b2e8b]
Login

Artifact 131b2e8bde3f6dc5be4dd78b89aee8146b709f90:

Attachment "primary-selection-problem.tcl" to ticket [de156e9e] added by kjnash 2017-06-13 18:04:47.
#! /usr/bin/env wish

set script {
    pack [text  .text -width 40 -height 8 -bg white] -pady 5
    if {[interp issafe]} {
        .text insert end "A safe interpreter is \"safe\" to run\nuntrusted\
                code.  So there's nothing to\nsee\
                here. Move along now."
        .text tag add sel 1.23 1.27
    } else {
        .text insert end "An unsafe interpreter's script can\nwrite\
                to the PRIMARY selection at any\ntime.\
                You must trust the author of any\nscript\
                that you run in an unsafe\ninterpreter\
                not to abuse this privilege\n(and\
                many others)."
        .text tag add sel 2.13 2.20
    }

    # Use the selection in an unmapped text widget to
    # manipulate the PRIMARY selection.
    # When this happens, the mapped text
    # widget loses its selection.
    text .t2
    .t2 insert end PAYLOAD
    proc TryAgain {} {
        .t2 tag remove sel 1.0 end-1c
        after 400 .t2 tag add sel 1.0 end-1c
        after 5000 TryAgain
        return
    }
    after 5000 TryAgain
}

# To run in the master interpreter.
# eval $script

# To run in a slave interpreter.
set int slave1
::safe::interpCreate $int
::safe::loadTk $int
$int eval $script