2015-09-25 21:37:19 +02:00
|
|
|
// File: fapplication.cpp
|
|
|
|
// Provides: class FApplication
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#include "fapp.h"
|
2015-10-23 00:24:20 +02:00
|
|
|
#include "fmenu.h"
|
2015-11-08 21:50:41 +01:00
|
|
|
#include "fstatusbar.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
#include "fwindow.h"
|
|
|
|
|
|
|
|
// global application object
|
|
|
|
static FApplication* rootObj = 0;
|
|
|
|
|
|
|
|
// flag to exit local loop
|
|
|
|
static bool app_exit_loop = false;
|
|
|
|
|
|
|
|
// static attributes
|
2016-10-01 23:18:49 +02:00
|
|
|
int FApplication::loop_level = 0; // event loop level
|
|
|
|
FWidget* FApplication::main_widget = 0; // main application widget
|
|
|
|
FWidget* FApplication::active_window = 0; // the active window
|
|
|
|
FWidget* FApplication::focus_widget = 0; // has keyboard input focus
|
|
|
|
FWidget* FApplication::clicked_widget = 0; // is focused by click
|
|
|
|
FWidget* FApplication::open_menu = 0; // currently open menu
|
2016-10-06 23:15:09 +02:00
|
|
|
FWidget* FApplication::move_size_widget = 0; // move/size by keyboard
|
2016-10-01 23:18:49 +02:00
|
|
|
FPoint* FApplication::zero_point = 0; // zero point (x=0, y=0)
|
|
|
|
int FApplication::quit_code = 0;
|
|
|
|
bool FApplication::quit_now = false;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
std::deque<FApplication::eventPair>* FApplication::event_queue = 0;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FApplication
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2016-02-07 22:02:38 +01:00
|
|
|
FApplication::FApplication (int& _argc, char**& _argv)
|
2016-07-30 23:00:37 +02:00
|
|
|
: FWidget(0)
|
|
|
|
, app_argc(_argc)
|
2016-02-07 22:02:38 +01:00
|
|
|
, app_argv(_argv)
|
2015-10-03 01:45:13 +02:00
|
|
|
, skipped_terminal_update(0)
|
2015-09-22 04:18:20 +02:00
|
|
|
, key(0)
|
|
|
|
#ifdef F_HAVE_LIBGPM
|
|
|
|
, gpm_ev()
|
|
|
|
, gpmMouseEvent(false)
|
|
|
|
#endif
|
|
|
|
, b_state()
|
|
|
|
, fifo_offset(0)
|
|
|
|
, fifo_in_use(false)
|
|
|
|
, fifo_buf_size(sizeof(fifo_buf))
|
2015-10-07 21:32:30 +02:00
|
|
|
, key_timeout(100000) // 100 ms
|
2015-09-22 04:18:20 +02:00
|
|
|
, dblclick_interval(500000) // 500 ms
|
|
|
|
, time_keypressed()
|
|
|
|
, time_mousepressed()
|
2016-09-27 00:46:05 +02:00
|
|
|
, new_mouse_position()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
assert ( ! rootObj
|
|
|
|
&& "FApplication: There should be only one application object" );
|
|
|
|
rootObj = this;
|
|
|
|
|
2016-08-21 21:27:44 +02:00
|
|
|
if ( ! (_argc && _argv) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-02-07 22:02:38 +01:00
|
|
|
static char* empty = const_cast<char*>("");
|
2015-09-20 05:44:50 +02:00
|
|
|
_argc = 0;
|
2016-02-07 22:02:38 +01:00
|
|
|
_argv = static_cast<char**>(&empty);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-02-07 22:02:38 +01:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FApplication::~FApplication() // destructor
|
|
|
|
{
|
|
|
|
if ( zero_point )
|
|
|
|
delete zero_point;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( event_queue )
|
|
|
|
delete event_queue;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
rootObj = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FApplication
|
|
|
|
//----------------------------------------------------------------------
|
2016-02-07 22:02:38 +01:00
|
|
|
void FApplication::init()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
// init keyboard values
|
|
|
|
time_keypressed.tv_sec = 0;
|
|
|
|
time_keypressed.tv_usec = 0;
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
x11_button_state = 0x23;
|
2015-08-22 18:53:52 +02:00
|
|
|
#ifdef F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
gpm_ev.x = -1;
|
|
|
|
#endif
|
|
|
|
zero_point = new FPoint(0,0);
|
|
|
|
event_queue = new std::deque<eventPair>;
|
|
|
|
// init arrays with '\0'
|
|
|
|
std::fill_n (k_buf, sizeof(k_buf), '\0');
|
|
|
|
std::fill_n (fifo_buf, fifo_buf_size, '\0');
|
|
|
|
std::fill_n (x11_mouse, sizeof(x11_mouse), '\0');
|
|
|
|
std::fill_n (sgr_mouse, sizeof(sgr_mouse), '\0');
|
|
|
|
std::fill_n (urxvt_mouse, sizeof(urxvt_mouse), '\0');
|
|
|
|
// init bit field with 0
|
2016-10-06 23:15:09 +02:00
|
|
|
std::memset(&b_state, 0x00, sizeof(b_state));
|
2015-05-23 13:35:12 +02:00
|
|
|
// interpret the command line options
|
|
|
|
cmd_options();
|
|
|
|
}
|
|
|
|
|
2016-08-28 22:43:14 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::setExitMessage (std::string message)
|
|
|
|
{
|
|
|
|
quit_now = true;
|
2016-10-06 23:15:09 +02:00
|
|
|
std::snprintf ( FTerm::exit_message
|
|
|
|
, sizeof(FTerm::exit_message)
|
|
|
|
, "%s"
|
|
|
|
, message.c_str() );
|
2016-08-28 22:43:14 +02:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::cmd_options ()
|
|
|
|
{
|
|
|
|
while ( true )
|
|
|
|
{
|
|
|
|
int c, idx = 0;
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
2015-12-21 18:37:20 +01:00
|
|
|
{"encoding", required_argument, 0, 0 },
|
|
|
|
{"no-optimized-cursor", no_argument, 0, 0 },
|
|
|
|
{"vgafont", no_argument, 0, 0 },
|
|
|
|
{"newfont", no_argument, 0, 0 },
|
|
|
|
{0, 0, 0, 0 }
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
opterr = 0;
|
2015-09-24 00:41:43 +02:00
|
|
|
c = getopt_long ( app_argc
|
|
|
|
, app_argv
|
|
|
|
, ""
|
|
|
|
, long_options
|
|
|
|
, &idx );
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( c == -1 )
|
|
|
|
break;
|
2015-09-24 00:41:43 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( c == 0 )
|
|
|
|
{
|
2016-10-06 23:15:09 +02:00
|
|
|
if ( std::strcmp(long_options[idx].name, "encoding") == 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
FString encoding(optarg);
|
|
|
|
encoding = encoding.toUpper();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( encoding.includes("UTF8")
|
|
|
|
|| encoding.includes("VT100")
|
|
|
|
|| encoding.includes("PC")
|
|
|
|
|| encoding.includes("ASCII") )
|
|
|
|
{
|
|
|
|
setEncoding(encoding.c_str());
|
|
|
|
}
|
2016-08-28 22:43:14 +02:00
|
|
|
else
|
|
|
|
setExitMessage ( "Unknown encoding "
|
|
|
|
+ std::string(encoding.c_str()) );
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2015-12-21 18:37:20 +01:00
|
|
|
|
2016-10-06 23:15:09 +02:00
|
|
|
if ( std::strcmp(long_options[idx].name, "no-optimize-cursor") == 0 )
|
2015-12-21 18:37:20 +01:00
|
|
|
setCursorOptimisation (false);
|
|
|
|
|
2016-10-06 23:15:09 +02:00
|
|
|
if ( std::strcmp(long_options[idx].name, "vgafont") == 0 )
|
2016-08-28 22:43:14 +02:00
|
|
|
{
|
|
|
|
bool ret = setVGAFont();
|
|
|
|
|
|
|
|
if ( ! ret )
|
|
|
|
setExitMessage ("VGAfont is not supported by this terminal");
|
|
|
|
}
|
2015-12-21 18:37:20 +01:00
|
|
|
|
2016-10-06 23:15:09 +02:00
|
|
|
if ( std::strcmp(long_options[idx].name, "newfont") == 0 )
|
2016-08-28 22:43:14 +02:00
|
|
|
{
|
|
|
|
bool ret = setNewFont();
|
|
|
|
|
|
|
|
if ( ! ret )
|
|
|
|
setExitMessage ("Newfont is not supported by this terminal");
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-08-22 18:53:52 +02:00
|
|
|
#ifdef F_HAVE_LIBGPM
|
2015-10-17 19:40:43 +02:00
|
|
|
int FApplication::gpmEvent (bool clear)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
register int result;
|
|
|
|
register int max = (gpm_fd > stdin_no) ? gpm_fd : stdin_no;
|
|
|
|
fd_set ifds;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
FD_ZERO(&ifds);
|
|
|
|
FD_SET(stdin_no, &ifds);
|
|
|
|
FD_SET(gpm_fd, &ifds);
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 100000; // 100 ms
|
|
|
|
result = select (max+1, &ifds, 0, 0, &tv);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( FD_ISSET(stdin_no, &ifds) )
|
|
|
|
{
|
2015-10-03 01:45:13 +02:00
|
|
|
if ( clear )
|
|
|
|
FD_CLR (stdin_no, &ifds);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return keyboard_event;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-03 01:45:13 +02:00
|
|
|
if ( clear && FD_ISSET(gpm_fd, &ifds) )
|
2015-05-23 13:35:12 +02:00
|
|
|
FD_CLR (gpm_fd, &ifds);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if (result > 0)
|
|
|
|
return mouse_event;
|
|
|
|
else
|
|
|
|
return no_event;
|
|
|
|
}
|
2015-08-22 18:53:52 +02:00
|
|
|
#endif // F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FApplication::KeyPressed()
|
|
|
|
{
|
|
|
|
register int result;
|
|
|
|
fd_set ifds;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
FD_ZERO(&ifds);
|
|
|
|
FD_SET(stdin_no, &ifds);
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 100000; // 100 ms
|
|
|
|
result = select (stdin_no+1, &ifds, 0, 0, &tv);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( FD_ISSET(stdin_no, &ifds) )
|
|
|
|
FD_CLR (stdin_no, &ifds);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return (result > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline ssize_t FApplication::readKey()
|
|
|
|
{
|
|
|
|
register ssize_t bytes;
|
|
|
|
setNonBlockingInput();
|
|
|
|
bytes = read(stdin_no, &k_buf, sizeof(k_buf)-1);
|
|
|
|
unsetNonBlockingInput();
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::processKeyboardEvent()
|
|
|
|
{
|
|
|
|
bool isKeyPressed = false;
|
|
|
|
FWidget* widget = 0;
|
|
|
|
|
|
|
|
if ( focus_widget )
|
2016-09-30 04:55:28 +02:00
|
|
|
{
|
2016-10-01 23:18:49 +02:00
|
|
|
if ( move_size_widget )
|
|
|
|
widget = move_size_widget;
|
2016-09-30 04:55:28 +02:00
|
|
|
else
|
|
|
|
widget = focus_widget;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
|
|
|
{
|
2016-09-30 04:55:28 +02:00
|
|
|
widget = main_widget;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( widget->numOfChildren() >= 1 )
|
|
|
|
widget->focusFirstChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
// empty the buffer on timeout
|
|
|
|
if ( fifo_in_use && widget->isKeyTimeout(&time_keypressed, key_timeout) )
|
|
|
|
{
|
|
|
|
fifo_offset = 0;
|
|
|
|
key = 0;
|
|
|
|
std::fill_n (fifo_buf, fifo_buf_size, '\0');
|
|
|
|
fifo_in_use = false;
|
|
|
|
}
|
|
|
|
|
2015-10-03 01:45:13 +02:00
|
|
|
flush_out();
|
|
|
|
|
2015-08-22 18:53:52 +02:00
|
|
|
#ifdef F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_mouse_enabled )
|
|
|
|
{
|
|
|
|
gpmMouseEvent = false;
|
|
|
|
int type = gpmEvent();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
case mouse_event:
|
|
|
|
gpmMouseEvent = true;
|
|
|
|
break;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
case keyboard_event:
|
|
|
|
isKeyPressed = true;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
isKeyPressed = KeyPressed();
|
|
|
|
#else // without gpm
|
|
|
|
isKeyPressed = KeyPressed();
|
2015-08-22 18:53:52 +02:00
|
|
|
#endif // F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( isKeyPressed )
|
|
|
|
{
|
|
|
|
register ssize_t bytesread;
|
|
|
|
widget->getCurrentTime(time_keypressed);
|
|
|
|
x11_mouse[0] = sgr_mouse[0] = urxvt_mouse[0] = '\0';
|
|
|
|
|
|
|
|
if ( quit_now || app_exit_loop )
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ( (bytesread = readKey()) > 0 )
|
|
|
|
{
|
2015-09-24 00:41:43 +02:00
|
|
|
if ( bytesread + fifo_offset <= fifo_buf_size )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
for (int i=0; i < bytesread; i++)
|
|
|
|
{
|
|
|
|
fifo_buf[fifo_offset] = k_buf[i];
|
|
|
|
fifo_offset++;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
fifo_in_use = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the rest from the fifo buffer
|
|
|
|
while ( ! widget->isKeyTimeout(&time_keypressed, key_timeout)
|
2015-10-03 01:45:13 +02:00
|
|
|
&& fifo_offset > 0
|
2015-05-23 13:35:12 +02:00
|
|
|
&& key != NEED_MORE_DATA )
|
|
|
|
{
|
|
|
|
key = FTerm::parseKeyString(fifo_buf, fifo_buf_size, &time_keypressed);
|
|
|
|
|
|
|
|
if ( key != NEED_MORE_DATA )
|
|
|
|
{
|
2016-07-23 19:50:28 +02:00
|
|
|
key = modifierKeyCorrection (key);
|
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
switch ( key )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-07-28 23:38:17 +02:00
|
|
|
case fc::Fckey_l: // Ctrl-L (redraw the screen)
|
|
|
|
redraw();
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
case fc::Fkey_mouse:
|
2016-07-25 23:50:57 +02:00
|
|
|
{
|
2016-07-28 23:38:17 +02:00
|
|
|
int n;
|
|
|
|
const int len = 6;
|
|
|
|
x11_mouse[0] = fifo_buf[3];
|
|
|
|
x11_mouse[1] = fifo_buf[4];
|
|
|
|
x11_mouse[2] = fifo_buf[5];
|
|
|
|
x11_mouse[3] = '\0';
|
|
|
|
|
|
|
|
// Remove founded entry
|
|
|
|
for (n=len; n < fifo_buf_size; n++)
|
|
|
|
fifo_buf[n-len] = fifo_buf[n];
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
n = fifo_buf_size-len-1;
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
// Fill rest with '\0'
|
|
|
|
for (; n < fifo_buf_size; n++)
|
|
|
|
fifo_buf[n-len] = '\0';
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-10-01 23:18:49 +02:00
|
|
|
unprocessedInput() = bool(fifo_buf[0] != '\0');
|
2016-07-28 23:38:17 +02:00
|
|
|
processMouseEvent();
|
|
|
|
}
|
|
|
|
break;
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
case fc::Fkey_extended_mouse:
|
|
|
|
{
|
|
|
|
int n = 3;
|
2016-10-06 23:15:09 +02:00
|
|
|
int len = int(std::strlen(fifo_buf));
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
while ( n < len && n < fifo_buf_size )
|
|
|
|
{
|
|
|
|
sgr_mouse[n-3] = fifo_buf[n];
|
|
|
|
n++;
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
if ( fifo_buf[n] == 'M' || fifo_buf[n] == 'm' )
|
|
|
|
len = n + 1;
|
|
|
|
}
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
sgr_mouse[n-3] = '\0';
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
for (n=len; n < fifo_buf_size; n++) // Remove founded entry
|
|
|
|
fifo_buf[n-len] = fifo_buf[n];
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
n = fifo_buf_size-len-1;
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
for (; n < fifo_buf_size; n++) // Fill rest with '\0'
|
|
|
|
fifo_buf[n-len] = '\0';
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-10-01 23:18:49 +02:00
|
|
|
unprocessedInput() = bool(fifo_buf[0] != '\0');
|
2016-07-28 23:38:17 +02:00
|
|
|
processMouseEvent();
|
2016-07-25 23:50:57 +02:00
|
|
|
}
|
2016-07-28 23:38:17 +02:00
|
|
|
break;
|
2016-07-12 23:35:33 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
case fc::Fkey_urxvt_mouse:
|
2016-07-25 23:50:57 +02:00
|
|
|
{
|
2016-07-28 23:38:17 +02:00
|
|
|
int n = 2;
|
2016-10-06 23:15:09 +02:00
|
|
|
int len = int(std::strlen(fifo_buf));
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
while ( n < len && n < fifo_buf_size )
|
|
|
|
{
|
|
|
|
urxvt_mouse[n-2] = fifo_buf[n];
|
|
|
|
n++;
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
if ( fifo_buf[n] == 'M' || fifo_buf[n] == 'm' )
|
|
|
|
len = n + 1;
|
|
|
|
}
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
urxvt_mouse[n-2] = '\0';
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
for (n=len; n < fifo_buf_size; n++) // Remove founded entry
|
|
|
|
fifo_buf[n-len] = fifo_buf[n];
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
n = fifo_buf_size-len-1;
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
for (; n < fifo_buf_size; n++) // Fill rest with '\0'
|
|
|
|
fifo_buf[n-len] = '\0';
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-10-01 23:18:49 +02:00
|
|
|
unprocessedInput() = bool(fifo_buf[0] != '\0');
|
2016-07-28 23:38:17 +02:00
|
|
|
processMouseEvent();
|
|
|
|
}
|
|
|
|
break;
|
2016-07-25 23:50:57 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
// send key down event
|
|
|
|
FKeyEvent k_down_ev (fc::KeyDown_Event, key);
|
|
|
|
sendEvent (widget, &k_down_ev);
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
// send key press event
|
|
|
|
FKeyEvent k_press_ev (fc::KeyPress_Event, key);
|
|
|
|
sendEvent (widget, &k_press_ev);
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
if ( ! open_menu
|
|
|
|
&& ! k_press_ev.isAccepted()
|
|
|
|
&& ! k_down_ev.isAccepted() )
|
|
|
|
{
|
|
|
|
// switch to a specific dialog with Meta + 1..9
|
2016-10-06 23:15:09 +02:00
|
|
|
bool accpt = processDialogSwitchAccelerator();
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
// windows keyboard accelerator
|
|
|
|
if ( ! accpt )
|
|
|
|
{
|
2016-09-30 04:55:28 +02:00
|
|
|
FWidget* window = active_window;
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
if ( window )
|
|
|
|
accpt = processAccelerator (window);
|
|
|
|
}
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
// global keyboard accelerator
|
|
|
|
if ( ! accpt )
|
|
|
|
{
|
|
|
|
FWidget* root_widget = getRootWidget();
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-07-28 23:38:17 +02:00
|
|
|
if ( root_widget )
|
2016-10-06 23:15:09 +02:00
|
|
|
processAccelerator (root_widget);
|
2016-07-28 23:38:17 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-25 23:50:57 +02:00
|
|
|
}
|
2016-07-28 23:38:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
} // end of switch
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-06 23:15:09 +02:00
|
|
|
fifo_offset = int(std::strlen(fifo_buf));
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
// send key up event
|
2016-01-17 02:57:08 +01:00
|
|
|
FKeyEvent k_up_ev (fc::KeyUp_Event, key);
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (widget, &k_up_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
key = 0;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
std::fill_n (k_buf, sizeof(k_buf), '\0');
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// special case: Esc key
|
|
|
|
if ( fifo_in_use
|
|
|
|
&& fifo_offset == 1
|
|
|
|
&& fifo_buf[0] == 0x1b
|
|
|
|
&& fifo_buf[1] == 0x00
|
|
|
|
&& isKeyTimeout(&time_keypressed, key_timeout) )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FKeyEvent k_press_ev (fc::KeyPress_Event, fc::Fkey_escape);
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (widget, &k_press_ev);
|
2016-10-01 23:18:49 +02:00
|
|
|
unprocessedInput() = false;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 19:50:28 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-07-23 20:56:20 +02:00
|
|
|
int FApplication::modifierKeyCorrection (int& key_id)
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
|
|
|
// get the current modifier key state
|
|
|
|
getModifierKey();
|
|
|
|
modifier_key& m = mod_key;
|
|
|
|
|
2016-08-21 21:27:44 +02:00
|
|
|
if ( ! (m.shift || m.ctrl || m.alt) )
|
2016-07-23 19:59:55 +02:00
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:59:55 +02:00
|
|
|
}
|
|
|
|
else if ( m.shift && ! m.ctrl && ! m.alt )
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
switch ( key_id )
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
|
|
|
case fc::Fkey_up:
|
|
|
|
return fc::Fkey_sr; // Shift+Up
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
|
|
|
return fc::Fkey_sf; // Shift+Down
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
|
|
|
return fc::Fkey_sleft; // Shift+Left
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
|
|
|
return fc::Fkey_sright; // Shift+Right
|
|
|
|
|
|
|
|
case fc::Fkey_ic:
|
|
|
|
return fc::Fkey_sic; // Shift+Ins
|
|
|
|
|
|
|
|
case fc::Fkey_dc:
|
|
|
|
return fc::Fkey_sdc; // Shift+Del
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
|
|
|
return fc::Fkey_shome; // Shift+Home
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
return fc::Fkey_send; // Shift+End
|
|
|
|
|
|
|
|
case fc::Fkey_ppage:
|
|
|
|
return fc::Fkey_sprevious; // Shift+PgUp
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
|
|
|
return fc::Fkey_snext; // Shift+PgDn
|
|
|
|
|
|
|
|
default:
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:50:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( ! m.shift && m.ctrl && ! m.alt )
|
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
switch ( key_id )
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
|
|
|
case fc::Fkey_up:
|
|
|
|
return fc::Fckey_up; // Ctrl+Up
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
|
|
|
return fc::Fckey_down; // Ctrl+Down
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
|
|
|
return fc::Fckey_left; // Ctrl+Left
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
|
|
|
return fc::Fckey_right; // Ctrl+Right
|
|
|
|
|
|
|
|
case fc::Fkey_ic:
|
|
|
|
return fc::Fckey_ic; // Ctrl+Ins
|
|
|
|
|
|
|
|
case fc::Fkey_dc:
|
|
|
|
return fc::Fckey_dc; // Ctrl+Del
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
|
|
|
return fc::Fckey_home; // Ctrl+Home
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
return fc::Fckey_end; // Ctrl+End
|
|
|
|
|
|
|
|
case fc::Fkey_ppage:
|
|
|
|
return fc::Fckey_ppage; // Ctrl+PgUp
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
|
|
|
return fc::Fckey_npage; // Ctrl+PgDn
|
|
|
|
|
|
|
|
default:
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:50:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( ! m.shift && ! m.ctrl && m.alt )
|
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
switch ( key_id )
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
|
|
|
case fc::Fkey_up:
|
|
|
|
return fc::Fmkey_up; // Meta+Up
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
|
|
|
return fc::Fmkey_down; // Meta+Down
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
|
|
|
return fc::Fmkey_left; // Meta+Left
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
|
|
|
return fc::Fmkey_right; // Meta+Right
|
|
|
|
|
|
|
|
case fc::Fkey_ic:
|
|
|
|
return fc::Fmkey_ic; // Meta+Ins
|
|
|
|
|
|
|
|
case fc::Fkey_dc:
|
|
|
|
return fc::Fmkey_dc; // Meta+Del
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
|
|
|
return fc::Fmkey_home; // Meta+Home
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
return fc::Fmkey_end; // Meta+End
|
|
|
|
|
|
|
|
case fc::Fkey_ppage:
|
|
|
|
return fc::Fmkey_ppage; // Meta+PgUp
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
|
|
|
return fc::Fmkey_npage; // Meta+PgDn
|
|
|
|
|
|
|
|
default:
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:50:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( m.shift && m.ctrl && ! m.alt )
|
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
switch ( key_id )
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
|
|
|
case fc::Fkey_up:
|
|
|
|
return fc::Fckey_sup; // Shift+Ctrl+Up
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
|
|
|
return fc::Fckey_sdown; // Shift+Ctrl+Down
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
|
|
|
return fc::Fckey_sleft; // Shift+Ctrl+Left
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
|
|
|
return fc::Fckey_sright; // Shift+Ctrl+Right
|
|
|
|
|
|
|
|
case fc::Fkey_ic:
|
|
|
|
return fc::Fckey_sic; // Shift+Ctrl+Ins
|
|
|
|
|
|
|
|
case fc::Fkey_dc:
|
|
|
|
return fc::Fckey_sdc; // Shift+Ctrl+Del
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
|
|
|
return fc::Fckey_shome; // Shift+Ctrl+Home
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
return fc::Fckey_send; // Shift+Ctrl+End
|
|
|
|
|
|
|
|
case fc::Fkey_ppage:
|
|
|
|
return fc::Fckey_sppage; // Shift+Ctrl+PgUp
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
|
|
|
return fc::Fckey_snpage; // Shift+Ctrl+PgDn
|
|
|
|
|
|
|
|
default:
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:50:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( m.shift && ! m.ctrl && m.alt )
|
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
switch ( key_id )
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
|
|
|
case fc::Fkey_up:
|
|
|
|
return fc::Fmkey_sup; // Shift+Meta+Up
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
|
|
|
return fc::Fmkey_sdown; // Shift+Meta+Down
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
|
|
|
return fc::Fmkey_sright; // Shift+Meta+Left
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
|
|
|
return fc::Fmkey_sleft; // Shift+Meta+Right
|
|
|
|
|
|
|
|
case fc::Fkey_ic:
|
|
|
|
return fc::Fmkey_sic; // Shift+Meta+Ins
|
|
|
|
|
|
|
|
case fc::Fkey_dc:
|
|
|
|
return fc::Fmkey_sdc; // Shift+Meta+Del
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
|
|
|
return fc::Fmkey_shome; // Shift+Meta+Home
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
return fc::Fmkey_send; // Shift+Meta+End
|
|
|
|
|
|
|
|
case fc::Fkey_ppage:
|
|
|
|
return fc::Fmkey_sppage; // Shift+Meta+PgUp
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
|
|
|
return fc::Fmkey_snpage; // Shift+Meta+PgDn
|
|
|
|
|
|
|
|
default:
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:50:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( ! m.shift && m.ctrl && m.alt )
|
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
switch ( key_id )
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
|
|
|
case fc::Fkey_up:
|
|
|
|
return fc::Fcmkey_up; // Ctrl+Meta+Up
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
|
|
|
return fc::Fcmkey_down; // Ctrl+Meta+Down
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
|
|
|
return fc::Fcmkey_left; // Ctrl+Meta+Left
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
|
|
|
return fc::Fcmkey_right; // Ctrl+Meta+Right
|
|
|
|
|
|
|
|
case fc::Fkey_ic:
|
|
|
|
return fc::Fcmkey_ic; // Ctrl+Meta+Ins
|
|
|
|
|
|
|
|
case fc::Fkey_dc:
|
|
|
|
return fc::Fcmkey_dc; // Ctrl+Meta+Del
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
|
|
|
return fc::Fcmkey_home; // Ctrl+Meta+Home
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
return fc::Fcmkey_end; // Ctrl+Meta+End
|
|
|
|
|
|
|
|
case fc::Fkey_ppage:
|
|
|
|
return fc::Fcmkey_ppage; // Ctrl+Meta+PgUp
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
|
|
|
return fc::Fcmkey_npage; // Ctrl+Meta+PgDn
|
|
|
|
|
|
|
|
default:
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:50:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( m.shift && m.ctrl && m.alt )
|
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
switch ( key_id )
|
2016-07-23 19:50:28 +02:00
|
|
|
{
|
|
|
|
case fc::Fkey_up:
|
|
|
|
return fc::Fcmkey_sup; // Shift+Ctrl+Meta+Up
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
|
|
|
return fc::Fcmkey_sdown; // Shift+Ctrl+Meta+Down
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
|
|
|
return fc::Fcmkey_sleft; // Shift+Ctrl+Meta+Left
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
|
|
|
return fc::Fcmkey_sright; // Shift+Ctrl+Meta+Right
|
|
|
|
|
|
|
|
case fc::Fkey_ic:
|
|
|
|
return fc::Fcmkey_sic; // Shift+Ctrl+Meta+Ins
|
|
|
|
|
|
|
|
case fc::Fkey_dc:
|
|
|
|
return fc::Fcmkey_sdc; // Shift+Ctrl+Meta+Del
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
|
|
|
return fc::Fcmkey_shome; // Shift+Ctrl+Meta+Home
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
return fc::Fcmkey_send; // Shift+Ctrl+Meta+End
|
|
|
|
|
|
|
|
case fc::Fkey_ppage:
|
|
|
|
return fc::Fcmkey_sppage; // Shift+Ctrl+Meta+PgUp
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
|
|
|
return fc::Fcmkey_snpage; // Shift+Ctrl+Meta+PgDn
|
|
|
|
|
|
|
|
default:
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:50:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 20:56:20 +02:00
|
|
|
return key_id;
|
2016-07-23 19:50:28 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:39:38 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-07-24 20:18:23 +02:00
|
|
|
bool FApplication::processDialogSwitchAccelerator()
|
2016-07-16 20:39:38 +02:00
|
|
|
{
|
|
|
|
if ( key >= fc::Fmkey_1 && key <= fc::Fmkey_9 )
|
|
|
|
{
|
2016-07-23 20:56:20 +02:00
|
|
|
uLong n = uLong(key - fc::Fmkey_0);
|
|
|
|
uLong s = dialog_list->size();
|
2016-07-16 20:39:38 +02:00
|
|
|
|
|
|
|
if ( s > 0 && s >= n )
|
|
|
|
{
|
2016-09-30 04:55:28 +02:00
|
|
|
// unset the move/size mode
|
2016-10-02 21:26:25 +02:00
|
|
|
if ( move_size_widget )
|
|
|
|
{
|
|
|
|
FWidget* w = move_size_widget;
|
|
|
|
move_size_widget = 0;
|
|
|
|
w->redraw();
|
|
|
|
}
|
|
|
|
|
2016-07-16 20:39:38 +02:00
|
|
|
FAccelEvent a_ev (fc::Accelerator_Event, focus_widget);
|
|
|
|
sendEvent (dialog_list->at(n-1), &a_ev);
|
2016-07-24 20:18:23 +02:00
|
|
|
return true;
|
2016-07-16 20:39:38 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-24 20:18:23 +02:00
|
|
|
|
|
|
|
return false;
|
2016-07-16 20:39:38 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 23:35:33 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-07-25 23:50:57 +02:00
|
|
|
bool FApplication::processAccelerator (FWidget*& widget)
|
2016-07-12 23:35:33 +02:00
|
|
|
{
|
2016-07-24 20:18:23 +02:00
|
|
|
bool accpt = false;
|
|
|
|
|
2016-07-12 23:35:33 +02:00
|
|
|
if ( widget
|
|
|
|
&& widget->accelerator_list
|
|
|
|
&& ! widget->accelerator_list->empty() )
|
|
|
|
{
|
|
|
|
FWidget::Accelerators::const_iterator iter, end;
|
|
|
|
iter = widget->accelerator_list->begin();
|
|
|
|
end = widget->accelerator_list->end();
|
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
|
|
|
if ( quit_now || app_exit_loop )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ( iter->key == key )
|
|
|
|
{
|
2016-09-30 04:55:28 +02:00
|
|
|
// unset the move/size mode
|
2016-10-02 21:26:25 +02:00
|
|
|
if ( move_size_widget )
|
|
|
|
{
|
|
|
|
FWidget* w = move_size_widget;
|
|
|
|
move_size_widget = 0;
|
|
|
|
w->redraw();
|
|
|
|
}
|
|
|
|
|
2016-07-12 23:35:33 +02:00
|
|
|
FAccelEvent a_ev (fc::Accelerator_Event, focus_widget);
|
|
|
|
sendEvent (iter->object, &a_ev);
|
2016-07-24 20:18:23 +02:00
|
|
|
accpt = a_ev.isAccepted();
|
2016-07-12 23:35:33 +02:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
2016-07-24 20:18:23 +02:00
|
|
|
|
|
|
|
return accpt;
|
2016-07-12 23:35:33 +02:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-10-09 01:23:49 +02:00
|
|
|
void FApplication::getX11ButtonState (int button)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-10-09 01:23:49 +02:00
|
|
|
// get the x11 and urxvt mouse button state
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-10-09 01:23:49 +02:00
|
|
|
enum btn_states
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
key_shift = 0x04,
|
|
|
|
key_meta = 0x08,
|
|
|
|
key_ctrl = 0x10,
|
|
|
|
key_button_mask = 0x1c,
|
|
|
|
button1_pressed = 0x20,
|
|
|
|
button2_pressed = 0x21,
|
|
|
|
button3_pressed = 0x22,
|
|
|
|
all_buttons_released = 0x23,
|
|
|
|
button1_pressed_move = 0x40,
|
|
|
|
button2_pressed_move = 0x41,
|
|
|
|
button3_pressed_move = 0x42,
|
|
|
|
button_mask = 0x63,
|
|
|
|
button_up = 0x60,
|
2015-10-09 01:23:49 +02:00
|
|
|
button_down = 0x61,
|
|
|
|
button_up_move = 0x60,
|
|
|
|
button_down_move = 0x61
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
|
2015-10-09 01:23:49 +02:00
|
|
|
switch ( button )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
case button1_pressed:
|
|
|
|
case button1_pressed_move:
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( *mouse == new_mouse_position
|
2015-05-23 13:35:12 +02:00
|
|
|
&& x11_button_state == all_buttons_released
|
|
|
|
&& ! isKeyTimeout(&time_mousepressed, dblclick_interval) )
|
|
|
|
{
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.left_button = DoubleClick;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time_mousepressed = time_keypressed; // save click time
|
|
|
|
b_state.left_button = Pressed;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button2_pressed:
|
|
|
|
case button2_pressed_move:
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.middle_button = Pressed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button3_pressed:
|
|
|
|
case button3_pressed_move:
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.right_button = Pressed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case all_buttons_released:
|
|
|
|
switch ( x11_button_state & button_mask )
|
|
|
|
{
|
|
|
|
case button1_pressed:
|
|
|
|
case button1_pressed_move:
|
|
|
|
b_state.left_button = Released;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button2_pressed:
|
|
|
|
case button2_pressed_move:
|
|
|
|
b_state.middle_button = Released;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button3_pressed:
|
|
|
|
case button3_pressed_move:
|
|
|
|
b_state.right_button = Released;
|
|
|
|
break;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button_up:
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.wheel_up = Pressed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button_down:
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.wheel_down = Pressed;
|
|
|
|
break;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2015-10-09 01:23:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FApplication::parseX11Mouse()
|
|
|
|
{
|
|
|
|
uChar x, y;
|
|
|
|
|
|
|
|
enum x11_btn_states
|
|
|
|
{
|
|
|
|
key_shift = 0x04,
|
|
|
|
key_meta = 0x08,
|
|
|
|
key_ctrl = 0x10,
|
|
|
|
key_button_mask = 0x1c,
|
|
|
|
button1_pressed = 0x20,
|
|
|
|
button2_pressed = 0x21,
|
|
|
|
button3_pressed = 0x22,
|
|
|
|
all_buttons_released = 0x23,
|
|
|
|
button1_pressed_move = 0x40,
|
|
|
|
button2_pressed_move = 0x41,
|
|
|
|
button3_pressed_move = 0x42,
|
|
|
|
button_mask = 0x63,
|
|
|
|
button_up = 0x60,
|
|
|
|
button_down = 0x61
|
|
|
|
};
|
|
|
|
|
|
|
|
x = uChar(x11_mouse[1] - 0x20);
|
|
|
|
y = uChar(x11_mouse[2] - 0x20);
|
2016-09-27 00:46:05 +02:00
|
|
|
new_mouse_position.setPoint(x,y);
|
2016-07-23 19:50:28 +02:00
|
|
|
// fill bit field with 0
|
2016-10-06 23:15:09 +02:00
|
|
|
std::memset(&b_state, 0x00, sizeof(b_state));
|
2015-10-09 01:23:49 +02:00
|
|
|
|
|
|
|
if ( (x11_mouse[0] & key_shift) == key_shift )
|
|
|
|
b_state.shift_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-09 01:23:49 +02:00
|
|
|
if ( (x11_mouse[0] & key_meta) == key_meta )
|
|
|
|
b_state.meta_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-09 01:23:49 +02:00
|
|
|
if ( (x11_mouse[0] & key_ctrl) == key_ctrl )
|
|
|
|
b_state.control_button = Pressed;
|
|
|
|
|
|
|
|
if ( (x11_mouse[0] & button_mask) >= button1_pressed_move
|
|
|
|
&& (x11_mouse[0] & button_mask) <= button3_pressed_move
|
|
|
|
&& *mouse != *zero_point )
|
|
|
|
{
|
|
|
|
b_state.mouse_moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
getX11ButtonState (x11_mouse[0] & button_mask);
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( uChar(x11_mouse[1]) == mouse->getX() + 0x20
|
|
|
|
&& uChar(x11_mouse[2]) == mouse->getY() + 0x20
|
|
|
|
&& b_state.wheel_up != Pressed
|
|
|
|
&& b_state.wheel_down != Pressed
|
|
|
|
&& uChar(x11_mouse[0]) == x11_button_state )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
mouse->setPoint(x,y);
|
|
|
|
x11_button_state = uChar(x11_mouse[0]);
|
|
|
|
x11_mouse[0] = '\0';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FApplication::parseSGRMouse()
|
|
|
|
{
|
|
|
|
register char* p;
|
|
|
|
int button;
|
|
|
|
uChar x, y;
|
|
|
|
|
|
|
|
enum x11_ext_btn_states
|
|
|
|
{
|
|
|
|
key_shift = 0x04,
|
|
|
|
key_meta = 0x08,
|
|
|
|
key_ctrl = 0x10,
|
|
|
|
key_button_mask = 0x1c,
|
|
|
|
button1 = 0x00,
|
|
|
|
button2 = 0x01,
|
|
|
|
button3 = 0x02,
|
|
|
|
button1_move = 0x20,
|
|
|
|
button2_move = 0x21,
|
|
|
|
button3_move = 0x22,
|
|
|
|
button_mask = 0x63,
|
|
|
|
button_up = 0x40,
|
|
|
|
button_down = 0x41,
|
|
|
|
pressed = 'M',
|
|
|
|
released = 'm'
|
|
|
|
};
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
button = 0;
|
|
|
|
|
|
|
|
// parse the SGR mouse string
|
|
|
|
p = sgr_mouse;
|
|
|
|
|
|
|
|
while ( *p && *p != ';' )
|
|
|
|
{
|
|
|
|
if ( *p < '0' || *p > '9')
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
button = 10 * button + (*p - '0');
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( *p++ && *p != ';' )
|
|
|
|
{
|
|
|
|
if ( *p < '0' || *p > '9')
|
|
|
|
return false;
|
|
|
|
x = uChar(10 * x + (*p - '0'));
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( *p++ && *p != 'M' && *p != 'm' )
|
|
|
|
{
|
|
|
|
if ( *p < '0' || *p > '9')
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
y = uChar(10 * y + (*p - '0'));
|
|
|
|
}
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
new_mouse_position.setPoint(x,y);
|
2016-07-23 19:50:28 +02:00
|
|
|
// fill bit field with 0
|
2016-10-06 23:15:09 +02:00
|
|
|
std::memset(&b_state, 0x00, sizeof(b_state));
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( (button & key_shift) == key_shift )
|
|
|
|
b_state.shift_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( (button & key_meta) == key_meta )
|
|
|
|
b_state.meta_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( (button & key_ctrl) == key_ctrl )
|
|
|
|
b_state.control_button = Pressed;
|
|
|
|
|
|
|
|
if ( (button & button_mask) >= button1_move
|
|
|
|
&& (button & button_mask) <= button3_move
|
|
|
|
&& *mouse != *zero_point )
|
|
|
|
{
|
|
|
|
b_state.mouse_moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( *p == pressed )
|
|
|
|
{
|
|
|
|
switch ( button & button_mask )
|
|
|
|
{
|
|
|
|
case button1:
|
|
|
|
case button1_move:
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( *mouse == new_mouse_position
|
2015-05-23 13:35:12 +02:00
|
|
|
&& (((x11_button_state & 0x80) >> 2) + 'M') == released
|
|
|
|
&& ! isKeyTimeout(&time_mousepressed, dblclick_interval) )
|
|
|
|
{
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.left_button = DoubleClick;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time_mousepressed = time_keypressed; // save click time
|
|
|
|
b_state.left_button = Pressed;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button2:
|
|
|
|
case button2_move:
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.middle_button = Pressed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button3:
|
|
|
|
case button3_move:
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.right_button = Pressed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button_up:
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.wheel_up = Pressed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button_down:
|
|
|
|
time_mousepressed.tv_sec = 0;
|
|
|
|
time_mousepressed.tv_usec = 0;
|
|
|
|
b_state.wheel_down = Pressed;
|
|
|
|
break;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // *p == released
|
|
|
|
{
|
|
|
|
switch ( button & button_mask )
|
|
|
|
{
|
|
|
|
case button1:
|
|
|
|
case button1_move:
|
|
|
|
b_state.left_button = Released;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button2:
|
|
|
|
case button2_move:
|
|
|
|
b_state.middle_button = Released;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case button3:
|
|
|
|
case button3_move:
|
|
|
|
b_state.right_button = Released;
|
|
|
|
break;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( *mouse == new_mouse_position
|
2015-05-23 13:35:12 +02:00
|
|
|
&& b_state.wheel_up != Pressed
|
|
|
|
&& b_state.wheel_down != Pressed
|
|
|
|
&& x11_button_state == uChar(((*p & 0x20) << 2) + button) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
mouse->setPoint(x,y);
|
|
|
|
x11_button_state = uChar(((*p & 0x20) << 2) + button);
|
|
|
|
sgr_mouse[0] = '\0';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FApplication::parseUrxvtMouse()
|
|
|
|
{
|
|
|
|
register char* p;
|
|
|
|
register bool x_neg;
|
|
|
|
register bool y_neg;
|
|
|
|
int button;
|
|
|
|
uChar x, y;
|
|
|
|
|
|
|
|
enum urxvt_btn_states
|
|
|
|
{
|
|
|
|
key_shift = 0x04,
|
|
|
|
key_meta = 0x08,
|
|
|
|
key_ctrl = 0x10,
|
|
|
|
key_button_mask = 0x1c,
|
|
|
|
button1_pressed = 0x20,
|
|
|
|
button2_pressed = 0x21,
|
|
|
|
button3_pressed = 0x22,
|
|
|
|
all_buttons_released = 0x23,
|
|
|
|
button1_pressed_move = 0x40,
|
|
|
|
button2_pressed_move = 0x41,
|
|
|
|
button3_pressed_move = 0x42,
|
|
|
|
button_mask = 0x63,
|
|
|
|
button_up = 0x60,
|
|
|
|
button_down = 0x61,
|
|
|
|
button_up_move = 0x60,
|
|
|
|
button_down_move = 0x61
|
|
|
|
};
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
button = 0;
|
|
|
|
|
|
|
|
// parse the SGR mouse string
|
|
|
|
p = urxvt_mouse;
|
|
|
|
x_neg = false;
|
|
|
|
y_neg = false;
|
|
|
|
|
|
|
|
while ( *p && *p != ';' )
|
|
|
|
{
|
|
|
|
if ( *p < '0' || *p > '9')
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
button = 10 * button + (*p - '0');
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( *++p == '-' )
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
x_neg = true;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
while ( *p && *p != ';' )
|
|
|
|
{
|
|
|
|
if ( *p < '0' || *p > '9')
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
x = uChar(10 * x + (*p - '0'));
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( *++p == '-' )
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
y_neg = true;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
while ( *p && *p != 'M' )
|
|
|
|
{
|
|
|
|
if ( *p < '0' || *p > '9')
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
y = uChar(10 * y + (*p - '0'));
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( x_neg || x == 0 )
|
|
|
|
x = 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( y_neg || y == 0 )
|
|
|
|
y = 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( x > term->getWidth() )
|
|
|
|
x = uChar(term->getWidth());
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( y > term->getHeight() )
|
|
|
|
y = uChar(term->getHeight());
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
new_mouse_position.setPoint(x,y);
|
2016-07-23 19:50:28 +02:00
|
|
|
// fill bit field with 0
|
2016-10-06 23:15:09 +02:00
|
|
|
std::memset(&b_state, 0x00, sizeof(b_state));
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( (button & key_shift) == key_shift )
|
|
|
|
b_state.shift_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( (button & key_meta) == key_meta )
|
|
|
|
b_state.meta_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( (button & key_ctrl) == key_ctrl )
|
|
|
|
b_state.control_button = Pressed;
|
|
|
|
|
|
|
|
if ( (button & button_mask) >= button1_pressed_move
|
|
|
|
&& (button & button_mask) <= button3_pressed_move
|
|
|
|
&& *mouse != *zero_point )
|
|
|
|
{
|
|
|
|
b_state.mouse_moved = true;
|
|
|
|
}
|
|
|
|
|
2015-10-09 01:23:49 +02:00
|
|
|
getX11ButtonState (button & button_mask);
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( *mouse == new_mouse_position
|
2015-05-23 13:35:12 +02:00
|
|
|
&& b_state.wheel_up != Pressed
|
|
|
|
&& b_state.wheel_down != Pressed
|
|
|
|
&& x11_button_state == uChar(button) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
mouse->setPoint(x,y);
|
|
|
|
x11_button_state = uChar(button);
|
|
|
|
urxvt_mouse[0] = '\0';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-08-22 18:53:52 +02:00
|
|
|
#ifdef F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
bool FApplication::processGpmEvent()
|
|
|
|
{
|
2016-07-23 19:50:28 +02:00
|
|
|
// fill bit field with 0
|
2016-10-06 23:15:09 +02:00
|
|
|
std::memset(&b_state, 0x00, sizeof(b_state));
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( Gpm_GetEvent(&gpm_ev) == 1 )
|
|
|
|
{
|
|
|
|
Gpm_FitEvent (&gpm_ev);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.type & GPM_DRAG && gpm_ev.wdx == 0 && gpm_ev.wdy == 0 )
|
|
|
|
b_state.mouse_moved = true;
|
|
|
|
|
|
|
|
if ( gpm_ev.wdy > 0)
|
|
|
|
b_state.wheel_up = Pressed;
|
|
|
|
else if ( gpm_ev.wdy < 0)
|
|
|
|
b_state.wheel_down = Pressed;
|
|
|
|
|
|
|
|
switch ( gpm_ev.type & 0x0f )
|
|
|
|
{
|
|
|
|
case GPM_DOWN:
|
|
|
|
case GPM_DRAG:
|
|
|
|
if ( gpm_ev.buttons & GPM_B_LEFT )
|
|
|
|
{
|
|
|
|
if ( gpm_ev.type & GPM_DOUBLE )
|
|
|
|
b_state.left_button = DoubleClick;
|
|
|
|
else
|
|
|
|
b_state.left_button = Pressed;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.buttons & GPM_B_MIDDLE )
|
|
|
|
b_state.middle_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.buttons & GPM_B_RIGHT )
|
|
|
|
b_state.right_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.buttons & GPM_B_UP )
|
|
|
|
b_state.wheel_up = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.buttons & GPM_B_DOWN )
|
|
|
|
b_state.wheel_down = Pressed;
|
|
|
|
|
|
|
|
// keyboard modifiers
|
|
|
|
if ( gpm_ev.modifiers & (1 << KG_SHIFT) )
|
|
|
|
b_state.shift_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.modifiers & ((1 << KG_ALT) | (1 << KG_ALTGR)) )
|
|
|
|
b_state.meta_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.modifiers & (1 << KG_CTRL) )
|
|
|
|
b_state.control_button = Pressed;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPM_UP:
|
|
|
|
if ( gpm_ev.buttons & GPM_B_LEFT )
|
|
|
|
b_state.left_button = Released;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.buttons & GPM_B_MIDDLE )
|
|
|
|
b_state.middle_button = Released;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_ev.buttons & GPM_B_RIGHT )
|
|
|
|
b_state.right_button = Released;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
mouse->setPoint(gpm_ev.x, gpm_ev.y);
|
2015-10-03 01:45:13 +02:00
|
|
|
|
|
|
|
if ( gpmEvent(false) == mouse_event )
|
2016-10-01 23:18:49 +02:00
|
|
|
unprocessedInput() = true;
|
2015-10-03 01:45:13 +02:00
|
|
|
else
|
2016-10-01 23:18:49 +02:00
|
|
|
unprocessedInput() = false;
|
2015-10-03 01:45:13 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
GPM_DRAWPOINTER(&gpm_ev);
|
2015-10-03 01:45:13 +02:00
|
|
|
gpmMouseEvent = false;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-03 01:45:13 +02:00
|
|
|
gpmMouseEvent = false;
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-22 18:53:52 +02:00
|
|
|
#endif // F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::processMouseEvent()
|
|
|
|
{
|
2015-09-20 05:44:50 +02:00
|
|
|
bool Event = false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-08-22 18:53:52 +02:00
|
|
|
#ifdef F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! gpmMouseEvent
|
|
|
|
&& x11_mouse[0] == '\0'
|
|
|
|
&& sgr_mouse[0] == '\0'
|
|
|
|
&& urxvt_mouse[0] == '\0' )
|
2015-08-10 00:16:26 +02:00
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
2015-08-10 00:16:26 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ( x11_mouse[0] == '\0'
|
|
|
|
&& sgr_mouse[0] == '\0'
|
|
|
|
&& urxvt_mouse[0] == '\0' )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-08-22 18:53:52 +02:00
|
|
|
#ifdef F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpmMouseEvent )
|
2015-09-20 05:44:50 +02:00
|
|
|
Event = processGpmEvent();
|
2015-05-23 13:35:12 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( x11_mouse[0] )
|
2015-09-20 05:44:50 +02:00
|
|
|
Event = parseX11Mouse();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( sgr_mouse[0] )
|
2015-09-20 05:44:50 +02:00
|
|
|
Event = parseSGRMouse();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( urxvt_mouse[0] )
|
2015-09-20 05:44:50 +02:00
|
|
|
Event = parseUrxvtMouse();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
if ( ! Event )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! clicked_widget
|
|
|
|
&& ( b_state.left_button == Pressed
|
|
|
|
|| b_state.left_button == DoubleClick
|
|
|
|
|| b_state.right_button == Pressed
|
|
|
|
|| b_state.middle_button == Pressed
|
|
|
|
|| b_state.wheel_up == Pressed
|
|
|
|
|| b_state.wheel_down == Pressed ) )
|
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
// determine the window object on the current click position
|
2015-10-19 00:07:07 +02:00
|
|
|
FWidget* window = FWindow::getWindowWidgetAt (*mouse);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( window )
|
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
// determine the widget at the current click position
|
2015-10-17 19:40:43 +02:00
|
|
|
FWidget* child = childWidgetAt (window, *mouse);
|
2015-05-23 13:35:12 +02:00
|
|
|
clicked_widget = (child != 0) ? child : window;
|
|
|
|
}
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
// unset the move/size mode
|
2016-10-01 23:18:49 +02:00
|
|
|
if ( move_size_widget )
|
|
|
|
{
|
|
|
|
FWidget* w = move_size_widget;
|
|
|
|
move_size_widget = 0;
|
|
|
|
w->redraw();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2015-10-10 03:14:14 +02:00
|
|
|
|
2016-06-12 23:06:58 +02:00
|
|
|
// close the open menu
|
2015-10-23 00:24:20 +02:00
|
|
|
if ( open_menu && ! b_state.mouse_moved )
|
|
|
|
{
|
|
|
|
FMenu* menu = static_cast<FMenu*>(open_menu);
|
|
|
|
|
|
|
|
if ( ! menu->containsMenuStructure(*mouse) )
|
|
|
|
{
|
2016-08-20 22:27:23 +02:00
|
|
|
bool is_window_menu;
|
|
|
|
FWidget* super = menu->getSuperMenu();
|
|
|
|
|
|
|
|
if ( super && menu->isWindowsMenu(super) )
|
|
|
|
is_window_menu = true;
|
|
|
|
else
|
|
|
|
is_window_menu = false;
|
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
menu->unselectItem();
|
2015-10-23 00:24:20 +02:00
|
|
|
menu->hide();
|
|
|
|
menu->hideSubMenus();
|
|
|
|
menu->hideSuperMenus();
|
2015-11-08 21:50:41 +01:00
|
|
|
|
2016-08-20 22:27:23 +02:00
|
|
|
// No widget was been clicked and the menu is no dialog menu
|
2016-08-20 22:33:59 +02:00
|
|
|
if ( ! (clicked_widget || is_window_menu) )
|
2016-06-19 20:32:03 +02:00
|
|
|
FWindow::switchToPrevWindow();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-12-19 20:49:01 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-12-19 20:49:01 +01:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
2015-10-23 00:24:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:32:03 +02:00
|
|
|
// unselected menu bar item
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( ! open_menu && menuBar()
|
2015-11-07 23:16:09 +01:00
|
|
|
&& menuBar()->hasSelectedItem()
|
2015-11-05 23:25:21 +01:00
|
|
|
&& ! b_state.mouse_moved )
|
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( ! menuBar()->getTermGeometry().contains(*mouse) )
|
2015-11-05 23:25:21 +01:00
|
|
|
{
|
2016-06-19 20:32:03 +02:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->clearMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
menuBar()->resetMenu();
|
|
|
|
menuBar()->redraw();
|
2016-06-19 20:32:03 +02:00
|
|
|
|
|
|
|
// No widget was been clicked
|
|
|
|
if ( ! clicked_widget )
|
|
|
|
FWindow::switchToPrevWindow();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-06-19 20:32:03 +02:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-06-19 20:32:03 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
2015-11-05 23:25:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( clicked_widget )
|
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
FPoint widgetMousePos;
|
2015-05-23 13:35:12 +02:00
|
|
|
int key_state = 0;
|
|
|
|
|
|
|
|
if ( b_state.shift_button == Pressed )
|
2016-01-17 02:57:08 +01:00
|
|
|
key_state |= fc::ShiftButton;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( b_state.meta_button == Pressed )
|
2016-01-17 02:57:08 +01:00
|
|
|
key_state |= fc::MetaButton;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( b_state.control_button == Pressed )
|
2016-01-17 02:57:08 +01:00
|
|
|
key_state |= fc::ControlButton;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
widgetMousePos = clicked_widget->termToWidgetPos(*mouse);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( b_state.mouse_moved )
|
|
|
|
{
|
|
|
|
if ( b_state.left_button == Pressed )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_down_ev ( fc::MouseMove_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::LeftButton | key_state );
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (clicked_widget, &m_down_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( b_state.right_button == Pressed )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_down_ev ( fc::MouseMove_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::RightButton | key_state );
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (clicked_widget, &m_down_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( b_state.middle_button == Pressed )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_down_ev ( fc::MouseMove_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::MiddleButton | key_state );
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (clicked_widget, &m_down_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( b_state.left_button == DoubleClick )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_dblclick_ev ( fc::MouseDoubleClick_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::LeftButton | key_state );
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (clicked_widget, &m_dblclick_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else if ( b_state.left_button == Pressed )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_down_ev ( fc::MouseDown_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::LeftButton | key_state );
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (clicked_widget, &m_down_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else if ( b_state.left_button == Released )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_up_ev ( fc::MouseUp_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::LeftButton | key_state );
|
2015-05-23 13:35:12 +02:00
|
|
|
FWidget* released_widget = clicked_widget;
|
2016-07-25 23:50:57 +02:00
|
|
|
|
2015-10-23 00:24:20 +02:00
|
|
|
if ( b_state.right_button != Pressed
|
|
|
|
&& b_state.middle_button != Pressed )
|
|
|
|
clicked_widget = 0;
|
2016-07-25 23:50:57 +02:00
|
|
|
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (released_widget, &m_up_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( b_state.right_button == Pressed )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_down_ev ( fc::MouseDown_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::RightButton | key_state );
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (clicked_widget, &m_down_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else if ( b_state.right_button == Released )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_up_ev ( fc::MouseUp_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::RightButton | key_state );
|
2015-05-23 13:35:12 +02:00
|
|
|
FWidget* released_widget = clicked_widget;
|
2016-07-25 23:50:57 +02:00
|
|
|
|
2015-10-23 00:24:20 +02:00
|
|
|
if ( b_state.left_button != Pressed
|
|
|
|
&& b_state.middle_button != Pressed )
|
|
|
|
clicked_widget = 0;
|
2016-07-25 23:50:57 +02:00
|
|
|
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (released_widget, &m_up_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( b_state.middle_button == Pressed )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_down_ev ( fc::MouseDown_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::MiddleButton | key_state );
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (clicked_widget, &m_down_ev);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// gnome-terminal sends no released on middle click
|
|
|
|
if ( gnome_terminal )
|
|
|
|
clicked_widget = 0;
|
|
|
|
}
|
|
|
|
else if ( b_state.middle_button == Released )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FMouseEvent m_up_ev ( fc::MouseUp_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::MiddleButton | key_state );
|
2015-05-23 13:35:12 +02:00
|
|
|
FWidget* released_widget = clicked_widget;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-23 00:24:20 +02:00
|
|
|
if ( b_state.right_button != Pressed
|
|
|
|
&& b_state.left_button != Pressed )
|
2016-07-09 00:01:59 +02:00
|
|
|
{
|
|
|
|
clicked_widget = 0;
|
|
|
|
}
|
|
|
|
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (released_widget, &m_up_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-17 02:57:08 +01:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( b_state.wheel_up == Pressed )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FWheelEvent wheel_ev ( fc::MouseWheel_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::WheelUp );
|
2015-05-23 13:35:12 +02:00
|
|
|
FWidget* scroll_over_widget = clicked_widget;
|
|
|
|
clicked_widget = 0;
|
|
|
|
sendEvent(scroll_over_widget, &wheel_ev);
|
|
|
|
}
|
2016-01-17 02:57:08 +01:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( b_state.wheel_down == Pressed )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FWheelEvent wheel_ev ( fc::MouseWheel_Event
|
2016-09-25 23:53:48 +02:00
|
|
|
, widgetMousePos
|
2015-10-10 03:14:14 +02:00
|
|
|
, *mouse
|
2016-01-17 02:57:08 +01:00
|
|
|
, fc::WheelDown );
|
2015-05-23 13:35:12 +02:00
|
|
|
FWidget* scroll_over_widget = clicked_widget;
|
|
|
|
clicked_widget = 0;
|
2015-10-10 03:14:14 +02:00
|
|
|
sendEvent (scroll_over_widget, &wheel_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2015-08-11 00:11:07 +02:00
|
|
|
|
2015-08-22 18:53:52 +02:00
|
|
|
#ifdef F_HAVE_LIBGPM
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( gpm_mouse_enabled && gpm_ev.x != -1 )
|
|
|
|
GPM_DRAWPOINTER(&gpm_ev);
|
2015-08-10 00:18:36 +02:00
|
|
|
#endif
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::processResizeEvent()
|
|
|
|
{
|
|
|
|
if ( resize_term )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
FResizeEvent r_ev(fc::Resize_Event);
|
2015-05-23 13:35:12 +02:00
|
|
|
sendEvent(rootObj, &r_ev);
|
|
|
|
|
|
|
|
if ( r_ev.isAccepted() )
|
|
|
|
resize_term = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FApplication::processTimerEvent()
|
|
|
|
{
|
|
|
|
FObject::TimerList::iterator iter, end;
|
|
|
|
timeval currentTime;
|
|
|
|
int activated = 0;
|
|
|
|
|
|
|
|
getCurrentTime (currentTime);
|
|
|
|
|
2016-10-01 23:18:49 +02:00
|
|
|
if ( isTimerInUpdating() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( ! timer_list )
|
|
|
|
return 0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( timer_list->empty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
iter = timer_list->begin();
|
|
|
|
end = timer_list->end();
|
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( ! (*iter).id
|
|
|
|
|| ! (*iter).object
|
2015-05-23 13:35:12 +02:00
|
|
|
|| currentTime < (*iter).timeout ) // no timer expired
|
|
|
|
break;
|
|
|
|
|
|
|
|
(*iter).timeout += (*iter).interval;
|
|
|
|
|
|
|
|
if ( (*iter).timeout < currentTime )
|
|
|
|
(*iter).timeout = currentTime + (*iter).interval;
|
|
|
|
|
|
|
|
if ( (*iter).interval.tv_usec > 0 || (*iter).interval.tv_sec > 0 )
|
|
|
|
activated++;
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
FTimerEvent t_ev(fc::Timer_Event, (*iter).id);
|
2015-05-23 13:35:12 +02:00
|
|
|
sendEvent((*iter).object, &t_ev);
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return activated;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-06-25 14:33:43 +02:00
|
|
|
void FApplication::processTerminalUpdate()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-09-11 17:26:41 +02:00
|
|
|
const int max_skip = 8;
|
2016-07-10 00:23:39 +02:00
|
|
|
|
2015-10-03 01:45:13 +02:00
|
|
|
if ( terminal_update_pending )
|
|
|
|
{
|
2016-10-01 23:18:49 +02:00
|
|
|
if ( ! unprocessedInput() )
|
2015-10-03 01:45:13 +02:00
|
|
|
{
|
|
|
|
updateTerminal();
|
|
|
|
terminal_update_pending = false;
|
|
|
|
skipped_terminal_update = 0;
|
|
|
|
}
|
2016-09-11 17:26:41 +02:00
|
|
|
else if ( skipped_terminal_update > max_skip )
|
2015-10-03 01:45:13 +02:00
|
|
|
{
|
|
|
|
force_terminal_update = true;
|
|
|
|
updateTerminal();
|
|
|
|
force_terminal_update = false;
|
|
|
|
terminal_update_pending = false;
|
|
|
|
skipped_terminal_update = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
skipped_terminal_update++;
|
|
|
|
}
|
2016-06-25 14:33:43 +02:00
|
|
|
}
|
2015-10-03 01:45:13 +02:00
|
|
|
|
2016-06-25 14:33:43 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::processCloseWidget()
|
|
|
|
{
|
2016-07-06 23:11:49 +02:00
|
|
|
updateTerminal(false);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( close_widget && ! close_widget->empty() )
|
|
|
|
{
|
|
|
|
widgetList::iterator iter;
|
|
|
|
iter = close_widget->begin();
|
|
|
|
|
2016-07-16 20:39:38 +02:00
|
|
|
while ( iter != close_widget->end() && *iter )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-10-06 05:09:18 +02:00
|
|
|
delete *iter;
|
|
|
|
++iter;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-06 05:09:18 +02:00
|
|
|
close_widget->clear();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-10 00:23:39 +02:00
|
|
|
|
2016-07-06 23:11:49 +02:00
|
|
|
updateTerminal(true);
|
2016-06-25 14:33:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FApplication::processNextEvent()
|
|
|
|
{
|
|
|
|
int num_events = 0;
|
|
|
|
|
|
|
|
processKeyboardEvent();
|
|
|
|
processMouseEvent();
|
|
|
|
processResizeEvent();
|
|
|
|
processTerminalUpdate();
|
|
|
|
processCloseWidget();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
sendQueuedEvents();
|
|
|
|
num_events += processTimerEvent();
|
|
|
|
|
|
|
|
return (num_events > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// public methods of FApplication
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::print_cmd_Options ()
|
|
|
|
{
|
2016-10-06 23:15:09 +02:00
|
|
|
std::printf ( "\nFinalCut Options:\n"
|
2015-05-23 13:35:12 +02:00
|
|
|
" --encoding <name> Sets the character encoding mode\n"
|
|
|
|
" {UTF8, VT100, PC, ASCII}\n"
|
2015-12-21 18:37:20 +01:00
|
|
|
" --no-optimized-cursor No cursor optimisation\n"
|
2015-05-23 13:35:12 +02:00
|
|
|
" --vgafont Set the standard vga 8x16 font\n"
|
2016-10-06 23:15:09 +02:00
|
|
|
" --newfont Enables the graphical font\n" );
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::setMainWidget (FWidget* widget)
|
|
|
|
{
|
|
|
|
main_widget = widget;
|
|
|
|
|
|
|
|
if ( widget && ! getFocusWidget() )
|
|
|
|
rootObj->focusFirstChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FApplication::exec() // run
|
|
|
|
{
|
2016-08-28 22:43:14 +02:00
|
|
|
if ( quit_now )
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
quit_now = false;
|
|
|
|
quit_code = 0;
|
|
|
|
|
|
|
|
enter_loop();
|
|
|
|
return quit_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FApplication::enter_loop() // event loop
|
|
|
|
{
|
|
|
|
bool old_app_exit_loop;
|
|
|
|
loop_level++;
|
|
|
|
quit_now = false;
|
|
|
|
|
|
|
|
old_app_exit_loop = app_exit_loop;
|
|
|
|
app_exit_loop = false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-08-21 21:27:44 +02:00
|
|
|
while ( ! (quit_now || app_exit_loop) )
|
2015-05-23 13:35:12 +02:00
|
|
|
processNextEvent();
|
|
|
|
|
2016-07-09 00:01:59 +02:00
|
|
|
app_exit_loop = old_app_exit_loop;
|
2015-05-23 13:35:12 +02:00
|
|
|
loop_level--;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::exit_loop()
|
|
|
|
{
|
|
|
|
app_exit_loop = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::exit (int retcode)
|
|
|
|
{
|
|
|
|
if ( ! rootObj ) // no global app object
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( quit_now ) // don't overwrite quit code
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
quit_now = true;
|
|
|
|
quit_code = retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::quit()
|
|
|
|
{
|
|
|
|
FApplication::exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FApplication::isQuit()
|
|
|
|
{
|
|
|
|
if ( rootObj )
|
|
|
|
return quit_now;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FApplication::sendEvent(FObject* receiver, FEvent* event)
|
|
|
|
{
|
|
|
|
FWidget* widget;
|
|
|
|
|
|
|
|
if ( quit_now || app_exit_loop )
|
|
|
|
return false;
|
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( ! receiver )
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
widget = static_cast<FWidget*>(receiver);
|
|
|
|
|
|
|
|
if ( modal_dialogs > 0 )
|
|
|
|
{
|
|
|
|
FWidget* window;
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( widget->isWindowWidget() )
|
2015-05-23 13:35:12 +02:00
|
|
|
window = widget;
|
|
|
|
else
|
|
|
|
window = FWindow::getWindowWidget(widget);
|
|
|
|
|
|
|
|
// block events for widgets in non modal windows
|
2016-06-12 23:06:58 +02:00
|
|
|
if ( window
|
|
|
|
&& (window->getFlags() & fc::modal) == 0
|
2016-09-25 23:53:48 +02:00
|
|
|
&& ! window->isMenuWidget() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
switch ( event->type() )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
case fc::KeyPress_Event:
|
|
|
|
case fc::KeyUp_Event:
|
|
|
|
case fc::KeyDown_Event:
|
|
|
|
case fc::MouseDown_Event:
|
|
|
|
case fc::MouseUp_Event:
|
|
|
|
case fc::MouseDoubleClick_Event:
|
|
|
|
case fc::MouseWheel_Event:
|
|
|
|
case fc::MouseMove_Event:
|
|
|
|
case fc::FocusIn_Event:
|
|
|
|
case fc::FocusOut_Event:
|
|
|
|
case fc::Accelerator_Event:
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// throw away mouse events to disabled widgets
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( event->type() >= fc::MouseDown_Event
|
|
|
|
&& event->type() <= fc::MouseMove_Event
|
2015-05-23 13:35:12 +02:00
|
|
|
&& ! widget->isEnabled() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// sends event event directly to receiver
|
|
|
|
return widget->event(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::queueEvent (FObject* receiver, FEvent* event)
|
|
|
|
{
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( ! receiver )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// queue this event
|
|
|
|
eventPair Event (receiver, event);
|
|
|
|
event_queue->push_back(Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FApplication::sendQueuedEvents()
|
|
|
|
{
|
|
|
|
std::deque<eventPair>* events;
|
|
|
|
|
|
|
|
if ( ! eventInQueue() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
events = event_queue;
|
|
|
|
|
|
|
|
while ( ! eventInQueue() )
|
|
|
|
{
|
|
|
|
sendEvent(events->front().first, events->front().second);
|
|
|
|
events->pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FApplication::eventInQueue()
|
|
|
|
{
|
|
|
|
if ( rootObj )
|
|
|
|
return ( ! event_queue->empty() );
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FApplication::removeQueuedEvent(FObject* receiver)
|
|
|
|
{
|
|
|
|
bool retval;
|
|
|
|
std::deque<eventPair>::iterator iter;
|
|
|
|
|
|
|
|
if ( ! eventInQueue() )
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( ! receiver )
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
retval = false;
|
|
|
|
iter = event_queue->begin();
|
|
|
|
|
|
|
|
while ( iter != event_queue->end() )
|
|
|
|
{
|
|
|
|
if ( iter->first == receiver )
|
|
|
|
{
|
|
|
|
iter = event_queue->erase(iter);
|
|
|
|
retval = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return retval;
|
|
|
|
}
|