qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Patch: Ctrl+Ins to copy console on windows
@ 2005-11-20 11:25 art yerkes
  2005-11-20 17:45 ` Johannes Schindelin
  0 siblings, 1 reply; 4+ messages in thread
From: art yerkes @ 2005-11-20 11:25 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 450 bytes --]

This is a small patch to enable copying the current console to the clipboard
with Ctrl+Ins.
A line break is added after the last nonblank character of each copied line.

-- 
Here's a simple experiment. Stand on a train track between two locomotives
which are pushing on you with equal force in opposite directions. You will
exhibit no net motion. None the less, you may soon begin to notice that
something important is happening.
-- Robert Stirniman

[-- Attachment #2: qemu-copy-console.diff --]
[-- Type: text/x-patch, Size: 3290 bytes --]

Index: sdl.c
===================================================================
RCS file: /cvsroot/qemu/qemu/sdl.c,v
retrieving revision 1.23
diff -u -r1.23 sdl.c
--- sdl.c	30 Oct 2005 23:19:10 -0000	1.23
+++ sdl.c	20 Nov 2005 11:17:22 -0000
@@ -378,6 +378,7 @@
                         case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
                         case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
                         case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
+			case SDLK_INSERT: keysym = QEMU_KEY_CTRL_INS; break;
                         default: break;
                         }
                     } else {
Index: vl.h
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.h,v
retrieving revision 1.91
diff -u -r1.91 vl.h
--- vl.h	15 Nov 2005 22:16:05 -0000	1.91
+++ vl.h	20 Nov 2005 11:17:23 -0000
@@ -37,6 +37,9 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
 #include "audio/audio.h"
 
 #ifndef O_LARGEFILE
@@ -189,6 +192,7 @@
 #define QEMU_KEY_CTRL_END        0xe405
 #define QEMU_KEY_CTRL_PAGEUP     0xe406
 #define QEMU_KEY_CTRL_PAGEDOWN   0xe407
+#define QEMU_KEY_CTRL_INS        0xe408
 
 void kbd_put_keysym(int keysym);
 
Index: console.c
===================================================================
RCS file: /cvsroot/qemu/qemu/console.c,v
retrieving revision 1.3
diff -u -r1.3 console.c
--- console.c	9 Oct 2004 17:32:58 -0000	1.3
+++ console.c	20 Nov 2005 11:17:23 -0000
@@ -406,6 +406,67 @@
     console_show_cursor(s, 1);
 }
 
+static void console_copy() 
+{
+#ifdef _WIN32
+    TextConsole *s;
+    int i, j, copytotal = 0, lastline = 0, row;
+    char *copydest;
+    HGLOBAL clipbuf;
+
+    s = active_console;
+
+    // Count characters
+    for( i = 0; i < s->total_height; i++ ) {
+	row = 0;
+	for( j = 0; j < s->width; j++ ) {
+	    char ch = s->cells[i * s->width + j].ch;
+	    if( isprint(ch) && !isspace(ch) )
+		row = j;
+	}
+	if( row != 0 ) 
+	    lastline = i;
+	copytotal += row + strlen("\r\n");
+    }
+
+    // Create the clip buffer
+    if( !OpenClipboard( NULL ) ) return;
+
+    EmptyClipboard();
+    clipbuf = GlobalAlloc(GMEM_DDESHARE, copytotal+1);
+    
+    if( !clipbuf ) return;
+    
+    copydest = (char *)GlobalLock(clipbuf);
+    
+    // Copy the actual text
+    for( i = 0; i < lastline+1; i++ ) {
+	row = 0;
+	for( j = 0; j < s->width; j++ ) {
+	    char ch = s->cells[i * s->width + j].ch;
+	    if( isprint(ch) && !isspace(ch) )
+		row = j;
+	}
+	for( j = 0; j < row; j++ ) {
+	    char ch = s->cells[i * s->width + j].ch;
+	    if( isprint(ch) && !isspace(ch) ) 
+		*copydest++ = ch;
+	    else
+		*copydest++ = ' ';
+	}
+	*copydest++ = '\r';
+	*copydest++ = '\n';
+    }
+    
+    *copydest++ = 0;
+    
+    // Now set the clipboard
+    GlobalUnlock(clipbuf);
+    SetClipboardData(CF_TEXT,clipbuf);
+    CloseClipboard();
+#endif
+}
+
 static void console_scroll(int ydelta)
 {
     TextConsole *s;
@@ -641,6 +702,9 @@
     case QEMU_KEY_CTRL_PAGEDOWN:
         console_scroll(10);
         break;
+    case QEMU_KEY_CTRL_INS:
+	console_copy();
+	break;
     default:
         if (s->fd_read) {
             /* convert the QEMU keysym to VT100 key string */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] Patch: Ctrl+Ins to copy console on windows
  2005-11-20 11:25 [Qemu-devel] Patch: Ctrl+Ins to copy console on windows art yerkes
@ 2005-11-20 17:45 ` Johannes Schindelin
  2005-11-20 19:03   ` art yerkes
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2005-11-20 17:45 UTC (permalink / raw)
  To: qemu-devel

Hi,

On Sun, 20 Nov 2005, art yerkes wrote:

> This is a small patch to enable copying the current console to the clipboard
> with Ctrl+Ins.
> A line break is added after the last nonblank character of each copied line.
>
> +static void console_copy() 
> +{
> +#ifdef _WIN32

Thank you! I always wanted to run QEmu on my iBook and be able to copy the 
text into the clipboard!

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] Patch: Ctrl+Ins to copy console on windows
  2005-11-20 17:45 ` Johannes Schindelin
@ 2005-11-20 19:03   ` art yerkes
  2005-11-21 23:41     ` Jim C. Brown
  0 siblings, 1 reply; 4+ messages in thread
From: art yerkes @ 2005-11-20 19:03 UTC (permalink / raw)
  To: qemu-devel

On Sun, 20 Nov 2005 18:45:31 +0100 (CET)
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:

> Hi,
> 
> On Sun, 20 Nov 2005, art yerkes wrote:
> 
> > This is a small patch to enable copying the current console to the clipboard
> > with Ctrl+Ins.
> > A line break is added after the last nonblank character of each copied line.
> >
> > +static void console_copy() 
> > +{
> > +#ifdef _WIN32
> 
> Thank you! I always wanted to run QEmu on my iBook and be able to copy the 
> text into the clipboard!
> 
> Ciao,
> Dscho
> 

Unfortunately, I only implemented copying for windows.  I'm not sure
how the clipboard works on other platforms, but they can be added in
the console_copy function.

-- 
Here's a simple experiment. Stand on a train track between two locomotives
which are pushing on you with equal force in opposite directions. You will
exhibit no net motion. None the less, you may soon begin to notice that
something important is happening.
-- Robert Stirniman

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] Patch: Ctrl+Ins to copy console on windows
  2005-11-20 19:03   ` art yerkes
@ 2005-11-21 23:41     ` Jim C. Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Jim C. Brown @ 2005-11-21 23:41 UTC (permalink / raw)
  To: art yerkes; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1486 bytes --]

On Sun, Nov 20, 2005 at 11:03:26AM -0800, art yerkes wrote:
> > > This is a small patch to enable copying the current console to the clipboard
> > > with Ctrl+Ins.
> > > A line break is added after the last nonblank character of each copied line.
> > >
> > > +static void console_copy() 
> > > +{
> > > +#ifdef _WIN32
> > 
> Unfortunately, I only implemented copying for windows.  I'm not sure
> how the clipboard works on other platforms, but they can be added in
> the console_copy function.
> 

Thank you! This is great.

I've attached a modified version, which is more generic. Instead of copying to
the clipboard, it saves a copy of the text into a file named qemu-clip.txt
(in the working directory of qemu). Should work on all platforms. Needs a lot
of work (being able to specify the name of the file, append instead of overwrite,
etc.) but should make it easy to "cheat copy" (save it to a file and then copy
the text via a word processor).

I'll see if I can make it copy into the X clipboard directly (the entire
X clipboard system is built in a weird way though).

> -- 
> Here's a simple experiment. Stand on a train track between two locomotives
> which are pushing on you with equal force in opposite directions. You will
> exhibit no net motion. None the less, you may soon begin to notice that
> something important is happening.
> -- Robert Stirniman

I'll try this soon.

-- 
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.

[-- Attachment #2: qemu-put-console.diff --]
[-- Type: text/plain, Size: 2626 bytes --]

diff -ur qemu/console.c qemu.new/console.c
--- qemu/console.c	Thu Jan 27 23:09:49 2005
+++ qemu.new/console.c	Mon Nov 21 18:33:15 2005
@@ -406,6 +406,56 @@
     console_show_cursor(s, 1);
 }
 
+static void console_copy() 
+{
+    TextConsole *s;
+    int i, j, copytotal = 0, lastline = 0, row;
+    FILE *copydest;
+    HGLOBAL clipbuf;
+
+    s = active_console;
+
+    // Count characters
+    for( i = 0; i < s->total_height; i++ ) {
+	row = 0;
+	for( j = 0; j < s->width; j++ ) {
+	    char ch = s->cells[i * s->width + j].ch;
+	    if( isprint(ch) && !isspace(ch) )
+		row = j;
+	}
+	if( row != 0 ) 
+	    lastline = i;
+	copytotal += row + strlen("\r\n");
+    }
+
+    // Create the clip buffer
+    if( (copydest = fopen("qemu-clip.txt","w")) == NULL ) { printf("error opening qemu-clip.txt\n"); return; }
+
+    // Copy the actual text
+    for( i = 0; i < lastline+1; i++ ) {
+	row = 0;
+	for( j = 0; j < s->width; j++ ) {
+	    char ch = s->cells[i * s->width + j].ch;
+	    if( isprint(ch) && !isspace(ch) )
+		row = j;
+	}
+	for( j = 0; j < row; j++ ) {
+	    char ch = s->cells[i * s->width + j].ch;
+	    if( isprint(ch) && !isspace(ch) ) 
+		fputc(ch, copydest);
+	    else
+		fputc(' ', copydest);
+	}
+	// fputc('\r', copydest); /* don't need this since we've opened in text mode */
+	fputc('\n', copydest);
+    }
+    
+    //fputc(0, copydest);
+    
+    // Now set the clipboard
+    fclose(copydest);
+}
+
 static void console_scroll(int ydelta)
 {
     TextConsole *s;
@@ -641,6 +691,9 @@
     case QEMU_KEY_CTRL_PAGEDOWN:
         console_scroll(10);
         break;
+    case QEMU_KEY_CTRL_INS:
+	console_copy();
+	break;
     default:
         if (s->fd_read) {
             /* convert the QEMU keysym to VT100 key string */
diff -ur qemu/sdl.c qemu.new/sdl.c
--- qemu/sdl.c	Sat Nov  5 09:56:28 2005
+++ qemu.new/sdl.c	Mon Nov 21 18:28:02 2005
@@ -391,6 +387,7 @@
                         case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
                         case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
                         case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
+			case SDLK_INSERT: keysym = QEMU_KEY_CTRL_INS; break;
                         default: break;
                         }
                     } else {
diff -ur qemu/vl.h qemu.new/vl.h
--- qemu/vl.h	Tue Nov 15 18:19:19 2005
+++ qemu.new/vl.h	Mon Nov 21 18:28:36 2005
@@ -193,6 +193,7 @@
 #define QEMU_KEY_CTRL_END        0xe405
 #define QEMU_KEY_CTRL_PAGEUP     0xe406
 #define QEMU_KEY_CTRL_PAGEDOWN   0xe407
+#define QEMU_KEY_CTRL_INS        0xe408
 
 void kbd_put_keysym(int keysym);
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-11-21 23:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-20 11:25 [Qemu-devel] Patch: Ctrl+Ins to copy console on windows art yerkes
2005-11-20 17:45 ` Johannes Schindelin
2005-11-20 19:03   ` art yerkes
2005-11-21 23:41     ` Jim C. Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).