Cut&paste working in kmscon
Table of Contents
The necessary chore – libtsm
Reading through the sources of libtsm was the only way to learn about it. There is just no documentation. Only wlterm is stated as an example of how to use the API. But the exact details of how to use libtsm‘s calls for selection and text-copy features are not obvious *sigh* I never enjoy these types of tasks! It is one thing, when doing these chores during paid work. But when working on code for fun, during your spare-time, such obstacles are a total motivation killer IMO.
For quick reference I list the relevant calls I used here:
- tsm_screen_selection_reset() – resets/clears any selection
- tsm_screen_selection_start() – sets the beginning of a selection
- tsm_screen_selection_target() – sets the end of a selection
- tsm_screen_selection_copy() – creates an libtsm-internal copy of the text for later pasting
- kmscon_pty_write() – do the actual pasting of the marked/copied text
You do not buffer the selected text yourself, before pasting it. That all is handled by tsm_screen_selection_copy().
As you can see in the video/screencast above, selecting and pasting of text works now in kmscon… just like one is used to from old-school gpm (general purpose mouse-server). While not demonstrated in the video, this also applies to any variant of output-rotation.
What is missing
The slick visuals are still missing. Right now it looks like any ordinary text-selection tool out there. But clean and robust functionality comes first.
The mouse-cursor – or rather the visual representation of it – is not fully in sync with internals in some cases. That is due to the fact that I have to juggle OpenGL’s normalized screen-coordinates, text-based cell-coordinates and the high-DPI values of the mouse.
“Show me the code, baby!”
You find the current work-in-progress code here. Note that all work is happening in the mouse-support branch. But you would rather want to wait for me to have finished this, before talking a look.