- Stopped sending double the number of wheel events as appropriate to the

console under Linux.
- Added middle mouse button selection pasting for X systems.



SVN r1420 (trunk)
This commit is contained in:
Randy Heit 2009-02-10 02:16:41 +00:00
parent e55a97a18e
commit 035edb32ad
8 changed files with 112 additions and 79 deletions

View file

@ -1,3 +1,7 @@
February 9, 2009
- Stopped sending double the number of wheel events to the console under Linux.
- Added middle mouse button selection pasting for X systems.
February 8, 2009 (Changes by Graf Zahl) February 8, 2009 (Changes by Graf Zahl)
- Fixed parsing for MustConfirm key in skill parser. - Fixed parsing for MustConfirm key in skill parser.
- Converted internal MAPINFOs to new syntax. - Converted internal MAPINFOs to new syntax.
@ -5,7 +9,7 @@ February 8, 2009 (Changes by Graf Zahl)
- Restored Dehacked music name replacement. - Restored Dehacked music name replacement.
February 7, 2009 February 7, 2009
- Added GUICapture mouse events for Win32. - Added GUICapture mouse button events for Win32.
- Changed I_GetFromClipboard() to return an FString. - Changed I_GetFromClipboard() to return an FString.
- Added GTK+-based clipboard support for Linux. - Added GTK+-based clipboard support for Linux.
- Fixed: Most Linux filesystems do not fill in d_type for scandir(), so we - Fixed: Most Linux filesystems do not fill in d_type for scandir(), so we

View file

@ -108,6 +108,7 @@ static int TopLine, InsertLine;
static char *BufferRover = ConsoleBuffer; static char *BufferRover = ConsoleBuffer;
static void ClearConsole (); static void ClearConsole ();
static void C_PasteText(FString clip, BYTE *buffer, int len);
struct GameAtExit struct GameAtExit
{ {
@ -1735,42 +1736,22 @@ static bool C_HandleKey (event_t *ev, BYTE *buffer, int len)
buffer[2 + buffer[0]] = 0; buffer[2 + buffer[0]] = 0;
I_PutInClipboard ((char *)&buffer[2]); I_PutInClipboard ((char *)&buffer[2]);
} }
break;
} }
else else
{ // paste from clipboard { // paste from clipboard
FString clip = I_GetFromClipboard (); C_PasteText(I_GetFromClipboard(false), buffer, len);
if (clip.IsNotEmpty())
{
// Only paste the first line.
long brk = clip.IndexOfAny("\r\n\b");
int cliplen = brk >= 0 ? brk : clip.Len();
// Make sure there's room for the whole thing.
if (buffer[0] + cliplen > len)
{
cliplen = len - buffer[0];
}
if (cliplen > 0)
{
if (buffer[1] < buffer[0])
{
memmove (&buffer[2 + buffer[1] + cliplen],
&buffer[2 + buffer[1]], buffer[0] - buffer[1]);
}
memcpy (&buffer[2 + buffer[1]], clip, cliplen);
buffer[0] += cliplen;
buffer[1] += cliplen;
makestartposgood ();
HistPos = NULL;
}
}
break;
} }
break;
} }
break; break;
} }
break;
#ifdef unix
case EV_GUI_MButtonDown:
C_PasteText(I_GetFromClipboard(true), buffer, len);
break;
#endif
} }
// Ensure that the cursor is always visible while typing // Ensure that the cursor is always visible while typing
CursorTicker = C_BLINKRATE; CursorTicker = C_BLINKRATE;
@ -1778,6 +1759,36 @@ static bool C_HandleKey (event_t *ev, BYTE *buffer, int len)
return true; return true;
} }
static void C_PasteText(FString clip, BYTE *buffer, int len)
{
if (clip.IsNotEmpty())
{
// Only paste the first line.
long brk = clip.IndexOfAny("\r\n\b");
int cliplen = brk >= 0 ? brk : clip.Len();
// Make sure there's room for the whole thing.
if (buffer[0] + cliplen > len)
{
cliplen = len - buffer[0];
}
if (cliplen > 0)
{
if (buffer[1] < buffer[0])
{
memmove (&buffer[2 + buffer[1] + cliplen],
&buffer[2 + buffer[1]], buffer[0] - buffer[1]);
}
memcpy (&buffer[2 + buffer[1]], clip, cliplen);
buffer[0] += cliplen;
buffer[1] += cliplen;
makestartposgood ();
HistPos = NULL;
}
}
}
bool C_Responder (event_t *ev) bool C_Responder (event_t *ev)
{ {
if (ev->type != EV_GUI_Event || if (ev->type != EV_GUI_Event ||

View file

@ -152,7 +152,7 @@ bool CT_Responder (event_t *ev)
} }
else if (ev->data1 == 'V' && (ev->data3 & GKM_CTRL)) else if (ev->data1 == 'V' && (ev->data3 & GKM_CTRL))
{ {
CT_PasteChat(I_GetFromClipboard()); CT_PasteChat(I_GetFromClipboard(false));
} }
} }
else if (ev->subtype == EV_GUI_Char) else if (ev->subtype == EV_GUI_Char)
@ -169,10 +169,12 @@ bool CT_Responder (event_t *ev)
} }
return true; return true;
} }
#ifdef unix
else if (ev->subtype == EV_GUI_MButtonDown) else if (ev->subtype == EV_GUI_MButtonDown)
{ {
CT_PasteChat(I_GetFromClipboard()); CT_PasteChat(I_GetFromClipboard(true));
} }
#endif
} }
return false; return false;
@ -186,7 +188,7 @@ bool CT_Responder (event_t *ev)
void CT_PasteChat(const char *clip) void CT_PasteChat(const char *clip)
{ {
if (clip != NULL) if (clip != NULL && *clip != '\0')
{ {
// Only paste the first line. // Only paste the first line.
while (*clip != '\0') while (*clip != '\0')

View file

@ -285,14 +285,17 @@ static void WheelMoved(event_t *event)
{ {
if (GUICapture) if (GUICapture)
{ {
SDLMod mod = SDL_GetModState(); if (event->type != EV_KeyUp)
event->type = EV_GUI_Event; {
event->subtype = event->data1 == KEY_MWHEELUP ? EV_GUI_WheelUp : EV_GUI_WheelDown; SDLMod mod = SDL_GetModState();
event->data1 = 0; event->type = EV_GUI_Event;
event->data3 = ((mod & KMOD_SHIFT) ? GKM_SHIFT : 0) | event->subtype = event->data1 == KEY_MWHEELUP ? EV_GUI_WheelUp : EV_GUI_WheelDown;
((mod & KMOD_CTRL) ? GKM_CTRL : 0) | event->data1 = 0;
((mod & KMOD_ALT) ? GKM_ALT : 0); event->data3 = ((mod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
D_PostEvent(event); ((mod & KMOD_CTRL) ? GKM_CTRL : 0) |
((mod & KMOD_ALT) ? GKM_ALT : 0);
D_PostEvent(event);
}
} }
else else
{ {
@ -376,41 +379,51 @@ void MessagePump (const SDL_Event &sev)
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
event.type = sev.type == SDL_MOUSEBUTTONDOWN ? EV_KeyDown : EV_KeyUp; if (!GUICapture || sev.button.button == 4 || sev.button.button == 5)
/* These button mappings work with my Gentoo system using the
* evdev driver and a Logitech MX510 mouse. Whether or not they
* carry over to other Linux systems, I have no idea, but I sure
* hope so. (Though buttons 11 and 12 are kind of useless, since
* they also trigger buttons 4 and 5.)
*/
switch (sev.button.button)
{ {
case 1: event.data1 = KEY_MOUSE1; break; event.type = sev.type == SDL_MOUSEBUTTONDOWN ? EV_KeyDown : EV_KeyUp;
case 2: event.data1 = KEY_MOUSE3; break; /* These button mappings work with my Gentoo system using the
case 3: event.data1 = KEY_MOUSE2; break; * evdev driver and a Logitech MX510 mouse. Whether or not they
case 4: event.data1 = KEY_MWHEELUP; break; * carry over to other Linux systems, I have no idea, but I sure
case 5: event.data1 = KEY_MWHEELDOWN; break; * hope so. (Though buttons 11 and 12 are kind of useless, since
case 6: event.data1 = KEY_MOUSE4; break; /* dunno; not generated by my mouse */ * they also trigger buttons 4 and 5.)
case 7: event.data1 = KEY_MOUSE5; break; /* ditto */ */
case 8: event.data1 = KEY_MOUSE4; break; switch (sev.button.button)
case 9: event.data1 = KEY_MOUSE5; break; {
case 10: event.data1 = KEY_MOUSE6; break; case 1: event.data1 = KEY_MOUSE1; break;
case 11: event.data1 = KEY_MOUSE7; break; case 2: event.data1 = KEY_MOUSE3; break;
case 12: event.data1 = KEY_MOUSE8; break; case 3: event.data1 = KEY_MOUSE2; break;
default: printf("SDL mouse button %s %d\n", case 4: event.data1 = KEY_MWHEELUP; break;
sev.type == SDL_MOUSEBUTTONDOWN ? "down" : "up", sev.button.button); break; case 5: event.data1 = KEY_MWHEELDOWN; break;
case 6: event.data1 = KEY_MOUSE4; break; /* dunno; not generated by my mouse */
case 7: event.data1 = KEY_MOUSE5; break; /* ditto */
case 8: event.data1 = KEY_MOUSE4; break;
case 9: event.data1 = KEY_MOUSE5; break;
case 10: event.data1 = KEY_MOUSE6; break;
case 11: event.data1 = KEY_MOUSE7; break;
case 12: event.data1 = KEY_MOUSE8; break;
default: printf("SDL mouse button %s %d\n",
sev.type == SDL_MOUSEBUTTONDOWN ? "down" : "up", sev.button.button); break;
}
if (event.data1 != 0)
{
//DIKState[ActiveDIKState][event.data1] = (event.type == EV_KeyDown);
if (event.data1 == KEY_MWHEELUP || event.data1 == KEY_MWHEELDOWN)
{
WheelMoved(&event);
}
else
{
D_PostEvent(&event);
}
}
} }
if (event.data1 != 0) else if (sev.button.button >= 1 && sev.button.button <= 3)
{ {
//DIKState[ActiveDIKState][event.data1] = (event.type == EV_KeyDown); event.type = EV_GUI_Event;
if (event.data1 == KEY_MWHEELUP || event.data1 == KEY_MWHEELDOWN) event.subtype = sev.type == SDL_MOUSEBUTTONDOWN ? EV_GUI_LButtonDown : EV_GUI_LButtonUp;
{ event.subtype += (sev.button.button - 1) * 3;
WheelMoved(&event); D_PostEvent(&event);
}
else
{
D_PostEvent(&event);
}
} }
break; break;

View file

@ -2,7 +2,7 @@
#define __I_INPUT_H__ #define __I_INPUT_H__
void I_PutInClipboard (const char *str); void I_PutInClipboard (const char *str);
FString I_GetFromClipboard (); FString I_GetFromClipboard (bool use_primary_selection);
struct GUIDName struct GUIDName
{ {

View file

@ -587,21 +587,24 @@ void I_PutInClipboard (const char *str)
{ {
gtk_clipboard_set_text(clipboard, str, -1); gtk_clipboard_set_text(clipboard, str, -1);
} }
/* Should I? I don't know. It's not actually a selection.
clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
if (clipboard != NULL) if (clipboard != NULL)
{ {
gtk_clipboard_set_text(clipboard, str, -1); gtk_clipboard_set_text(clipboard, str, -1);
} }
*/
} }
#endif #endif
} }
FString I_GetFromClipboard () FString I_GetFromClipboard (bool use_primary_selection)
{ {
#ifndef NO_GTK #ifndef NO_GTK
if (GtkAvailable) if (GtkAvailable)
{ {
GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); GtkClipboard *clipboard = gtk_clipboard_get(use_primary_selection ?
GDK_SELECTION_PRIMARY : GDK_SELECTION_CLIPBOARD);
if (clipboard != NULL) if (clipboard != NULL)
{ {
gchar *text = gtk_clipboard_wait_for_text(clipboard); gchar *text = gtk_clipboard_wait_for_text(clipboard);

View file

@ -2041,14 +2041,14 @@ void I_PutInClipboard (const char *str)
CloseClipboard (); CloseClipboard ();
} }
FString I_GetFromClipboard () FString I_GetFromClipboard (bool return_nothing)
{ {
FString retstr; FString retstr;
HGLOBAL cliphandle; HGLOBAL cliphandle;
char *clipstr; char *clipstr;
char *nlstr; char *nlstr;
if (!IsClipboardFormatAvailable (CF_TEXT) || !OpenClipboard (Window)) if (return_nothing || !IsClipboardFormatAvailable (CF_TEXT) || !OpenClipboard (Window))
return retstr; return retstr;
cliphandle = GetClipboardData (CF_TEXT); cliphandle = GetClipboardData (CF_TEXT);

View file

@ -39,7 +39,7 @@
bool I_InitInput (void *hwnd); bool I_InitInput (void *hwnd);
void I_ShutdownInput (); void I_ShutdownInput ();
void I_PutInClipboard (const char *str); void I_PutInClipboard (const char *str);
FString I_GetFromClipboard (); FString I_GetFromClipboard (bool windows_has_no_selection_clipboard);
void I_GetEvent (); void I_GetEvent ();