mudgangster

Tiny, scriptable MUD client
Log | Files | Refs | README

commit d8b3aa9c458c9f76466c2cc249ed329e9eb2a34d
parent e87649773f91525453edae1e56d0240aed0b62d1
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun,  3 May 2020 12:15:44 +0300

Linux copy paste

Diffstat:
Mmake.lua | 6+++---
Msrc/platform_network.h | 12++++++------
Msrc/textbox.cc | 4----
Msrc/x11.cc | 34+++++++++++++++++++++++++++-------
4 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/make.lua b/make.lua @@ -1,6 +1,7 @@ require( "ggbuild.gen_ninja" ) require( "ggbuild.git_version" ) +require( "libs.libclipboard" ) require( "libs.tracy" ) require( "libs.whereami" ) @@ -20,7 +21,6 @@ if config ~= "release" then end local platform_srcs, platform_libs -local gcc_ldflags = config == "release" and "" or " -lpthread" if OS == "windows" then require( "libs.lua" ) @@ -31,7 +31,7 @@ if OS == "windows" then platform_libs = { "lua", "lpeg", "lfs" } else platform_srcs = "src/x11.cc" - platform_libs = { } + platform_libs = { "libclipboard" } end bin( "mudgangster", { @@ -49,7 +49,7 @@ bin( "mudgangster", { rc = "src/rc", msvc_extra_ldflags = "gdi32.lib Ws2_32.lib", - gcc_extra_ldflags = "-lm -lX11 -llua" .. gcc_ldflags, + gcc_extra_ldflags = "-lm -lpthread -lX11 -lxcb -llua", } ) obj_dependencies( "src/script.cc", "build/lua_combined.h" ) diff --git a/src/platform_network.h b/src/platform_network.h @@ -28,12 +28,12 @@ struct IPv4 { u8 bytes[ 4 ]; }; struct IPv6 { u8 bytes[ 16 ]; }; struct NetAddress { - IPvX type; - union { - IPv4 ipv4; - IPv6 ipv6; - }; - u16 port; + IPvX type; + union { + IPv4 ipv4; + IPv6 ipv6; + }; + u16 port; }; bool operator==( const NetAddress & lhs, const NetAddress & rhs ); diff --git a/src/textbox.cc b/src/textbox.cc @@ -212,7 +212,6 @@ void textbox_mouse_up( TextBox * tb, int window_x, int window_y ) { const TextBox::Line & line = tb->lines[ ( tb->head + tb->num_lines - tb->scroll_offset - i ) % tb->max_lines ]; size_t start_offset = i == start_line ? start_line_offset : 0; size_t end_offset = i == end_line ? end_line_offset : line.len; - printf( "%d: %zu-%zu\n", i, start_offset, end_offset ); // TODO: iterate over glyphs to see when ansi codes need inserting if( start_offset <= line.len ) { selected_length += min( line.len, end_offset ) - start_offset; @@ -222,9 +221,6 @@ void textbox_mouse_up( TextBox * tb, int window_x, int window_y ) { } } - printf( "%d+%zu to %d+%zu\n", start_line, start_line_offset, end_line, end_line_offset ); - printf( "%zu chars\n", selected_length ); - char * selected = ( char * ) malloc( selected_length ); selected[ selected_length - 1 ] = '\0'; diff --git a/src/x11.cc b/src/x11.cc @@ -14,6 +14,8 @@ #include "platform_ui.h" #include "platform_network.h" +#include "libclipboard/libclipboard.h" + struct Socket { TCPSocket sock; bool in_use; @@ -23,6 +25,8 @@ static Socket sockets[ 128 ]; static bool closing = false; +static clipboard_c * clipboard; + void * platform_connect( const char ** err, const char * host, int port ) { size_t idx; { @@ -356,7 +360,15 @@ static void event_key_press( XEvent * xevent ) { ADD_MACRO( XK_F12, "f12" ); default: - if( ctrl || alt ) { + if( ctrl && key == XK_v ) { + int len; + char * contents = clipboard_text_ex( clipboard, &len, LCB_CLIPBOARD ); + if( contents != NULL ) { + input_add( contents, len ); + free( contents ); + } + } + else if( ctrl || alt ) { script_doMacro( noShiftKeyBuffer, noShiftLen, shift, ctrl, alt ); } else if( len > 0 ) { @@ -532,11 +544,11 @@ void platform_ui_init() { void ui_urgent() { if( !UI.has_focus ) { - XWMHints * hints = XGetWMHints( UI.display, UI.window ); - hints->flags |= XUrgencyHint; - XSetWMHints( UI.display, UI.window, hints ); - XFree( hints ); - } + XWMHints * hints = XGetWMHints( UI.display, UI.window ); + hints->flags |= XUrgencyHint; + XSetWMHints( UI.display, UI.window, hints ); + XFree( hints ); + } } int ui_display_fd() { @@ -554,7 +566,8 @@ bool ui_set_font( const char * name, int size ) { } void platform_set_clipboard( const char * str, size_t len ) { - // TODO + // len includes the \0 + clipboard_set_text_ex( clipboard, str, len - 1, LCB_CLIPBOARD ); } void platform_ui_term() { @@ -584,6 +597,11 @@ int main() { platform_ui_init(); script_init(); + clipboard = clipboard_new( NULL ); + if( clipboard == NULL ) { + FATAL( "clipboard_new" ); + } + FrameMark; ui_handleXEvents(); @@ -632,6 +650,8 @@ int main() { ui_handleXEvents(); } + clipboard_free( clipboard ); + script_term(); platform_ui_term(); input_term();