Converted the internal timer from timeval to std::chrono::time_point<system_clock>

This commit is contained in:
Markus Gans 2021-06-16 15:42:46 +02:00
parent de4ac269e4
commit 85ae1612fd
19 changed files with 333 additions and 437 deletions

View File

@ -1,3 +1,7 @@
2021-06-16 Markus Gans <guru.mail@muenster.de>
* Converted the internal timer from timeval
to std::chrono::time_point<system_clock>
2021-06-06 Markus Gans <guru.mail@muenster.de>
* Bug fixing in FString and FTermDetection
* FTermDetection now has clean code by using FString instead of char*

View File

@ -43,7 +43,7 @@ fi
# Build commands
case "$1" in
"--release"|"release")
if ! ./configure --prefix="$PREFIX" CXXFLAGS="-O3" # "-fno-rtti"
if ! ./configure --prefix="$PREFIX" CXXFLAGS="-O3" # "-flto -fno-rtti"
then
echo "${RED}Configure failed!${NORMAL}" 1>&2
exit 255

View File

@ -110,15 +110,14 @@ Watch::Watch (FWidget* parent)
void Watch::printTime()
{
finalcut::FString str{};
std::tm now{};
const std::time_t t = std::time(nullptr); // get current time
localtime_r(&t, &now);
using namespace std::chrono;
auto now = system_clock::to_time_t(system_clock::now());
auto lt = *localtime(&now);
if ( sec )
str.sprintf("%02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec);
str.sprintf("%02d:%02d:%02d", lt.tm_hour, lt.tm_min, lt.tm_sec);
else
str.sprintf("%02d:%02d ", now.tm_hour, now.tm_min);
str.sprintf("%02d:%02d ", lt.tm_hour, lt.tm_min);
time_str = str;
time_str.redraw();

View File

@ -103,7 +103,7 @@ Special X11 bitmap font used by FINAL CUT to display graphic objects.
%build
autoreconf -vif
export CPPFLAGS="%{optflags} -Wall -Wextra -Wpedantic"
export CPPFLAGS="%{optflags} -Wall -Wextra -Wpedantic -flto"
%ifnarch %ix86 x86_64
export CPPFLAGS="$CPPFLAGS -Wno-error=unused-parameter"
%endif

View File

@ -72,7 +72,7 @@ int FApplication::loop_level {0}; // event loop level
int FApplication::quit_code {EXIT_SUCCESS};
bool FApplication::quit_now {false};
uInt64 FApplication::next_event_wait {5000}; // 5 ms (200 Hz)
struct timeval FApplication::time_last_event {};
TimeValue FApplication::time_last_event {};
//----------------------------------------------------------------------
@ -392,8 +392,7 @@ void FApplication::init()
setMaxChildren(1);
// Initialize the last event time
time_last_event.tv_sec = 0;
time_last_event.tv_usec = 0;
time_last_event = TimeValue{};
// Initialize keyboard
auto& keyboard = FTerm::getFKeyboard();
@ -858,7 +857,7 @@ void FApplication::queuingMouseInput() const
return;
auto& keyboard = FTerm::getFKeyboard();
struct timeval* time_keypressed = keyboard.getKeyPressedTime();
auto time_keypressed = keyboard.getKeyPressedTime();
mouse.processEvent (time_keypressed);
keyboard.hasUnprocessedInput() = mouse.hasUnprocessedInput();
mouse.clearEvent();
@ -1308,7 +1307,7 @@ bool FApplication::processNextEvent()
if ( is_timeout || hasDataInQueue() )
{
FObject::getCurrentTime (&time_last_event);
time_last_event = FObject::getCurrentTime();
queuingKeyboardInput();
queuingMouseInput();
processKeyboardEvent();
@ -1401,7 +1400,7 @@ bool FApplication::isEventProcessable ( FObject* receiver
//----------------------------------------------------------------------
bool FApplication::isNextEventTimeout()
{
return FObject::isTimeout (&time_last_event, next_event_wait);
return FObject::isTimeout (time_last_event, next_event_wait);
}

View File

@ -51,7 +51,7 @@ uInt64 FKeyboard::key_timeout{100000}; // 100 ms (10 Hz)
uInt64 FKeyboard::read_blocking_time{100000}; // 100 ms (10 Hz)
uInt64 FKeyboard::read_blocking_time_short{5000}; // 5 ms (200 Hz)
bool FKeyboard::non_blocking_input_support{true};
struct timeval FKeyboard::time_keypressed{};
TimeValue FKeyboard::time_keypressed{};
//----------------------------------------------------------------------
@ -63,8 +63,7 @@ struct timeval FKeyboard::time_keypressed{};
FKeyboard::FKeyboard()
{
// Initialize keyboard values
time_keypressed.tv_sec = 0;
time_keypressed.tv_usec = 0;
time_keypressed = TimeValue{}; // Set to epoch time
// Get the stdin file status flags
stdin_status_flags = fcntl(FTermios::getStdIn(), F_GETFL);
@ -392,7 +391,7 @@ inline FKey FKeyboard::getSingleKey()
//----------------------------------------------------------------------
inline bool FKeyboard::isKeypressTimeout()
{
return FObject::isTimeout (&time_keypressed, key_timeout);
return FObject::isTimeout (time_keypressed, key_timeout);
}
//----------------------------------------------------------------------
@ -457,7 +456,7 @@ inline ssize_t FKeyboard::readKey()
void FKeyboard::parseKeyBuffer()
{
ssize_t bytesread{};
FObject::getCurrentTime (&time_keypressed);
time_keypressed = FObject::getCurrentTime();
while ( (bytesread = readKey()) > 0 )
{

View File

@ -196,37 +196,37 @@ FString FMouse::getClassName() const
}
//----------------------------------------------------------------------
inline void FMouse::clearEvent()
void FMouse::clearEvent()
{
mouse_event_occurred = false;
}
//----------------------------------------------------------------------
inline void FMouse::setMaxWidth (uInt16 x_max)
void FMouse::setMaxWidth (uInt16 x_max)
{
max_width = x_max;
}
//----------------------------------------------------------------------
inline void FMouse::setMaxHeight (uInt16 y_max)
void FMouse::setMaxHeight (uInt16 y_max)
{
max_height = y_max;
}
//----------------------------------------------------------------------
inline void FMouse::setDblclickInterval (const uInt64 timeout)
void FMouse::setDblclickInterval (const uInt64 timeout)
{
dblclick_interval = timeout;
}
//----------------------------------------------------------------------
inline bool FMouse::hasEvent() const
bool FMouse::hasEvent() const
{
return mouse_event_occurred;
}
//----------------------------------------------------------------------
inline bool FMouse::hasUnprocessedInput() const
bool FMouse::hasUnprocessedInput() const
{
return unprocessed_buffer_data;
}
@ -234,7 +234,7 @@ inline bool FMouse::hasUnprocessedInput() const
// protected methods of FMouse
//----------------------------------------------------------------------
inline const FPoint& FMouse::getNewPos() const
const FPoint& FMouse::getNewPos() const
{
return new_mouse_position;
}
@ -258,9 +258,9 @@ uInt64 FMouse::getDblclickInterval() const
}
//----------------------------------------------------------------------
timeval* FMouse::getMousePressedTime()
TimeValue FMouse::getMousePressedTime()
{
return &time_mousepressed;
return time_mousepressed;
}
//----------------------------------------------------------------------
@ -276,16 +276,15 @@ void FMouse::setPending (bool is_pending)
}
//----------------------------------------------------------------------
void FMouse::setMousePressedTime (const timeval* time)
void FMouse::setMousePressedTime (const TimeValue& time)
{
time_mousepressed = *time;
time_mousepressed = time;
}
//----------------------------------------------------------------------
void FMouse::resetMousePressedTime()
{
time_mousepressed.tv_sec = 0;
time_mousepressed.tv_usec = 0;
time_mousepressed = TimeValue{}; // Set to epoch time
}
//----------------------------------------------------------------------
@ -295,7 +294,7 @@ void FMouse::setEvent()
}
//----------------------------------------------------------------------
bool FMouse::isDblclickTimeout (const timeval* time) const
bool FMouse::isDblclickTimeout (const TimeValue& time) const
{
return FObject::isTimeout (time, dblclick_interval);
}
@ -341,7 +340,7 @@ void FMouseGPM::setRawData (FKeyboard::keybuffer&)
}
//----------------------------------------------------------------------
void FMouseGPM::processEvent (struct timeval*)
void FMouseGPM::processEvent (const TimeValue&)
{
clearButtonState();
@ -582,7 +581,7 @@ void FMouseX11::setRawData (FKeyboard::keybuffer& fifo_buf)
}
//----------------------------------------------------------------------
void FMouseX11::processEvent (struct timeval* time)
void FMouseX11::processEvent (const TimeValue& time)
{
// Parse and interpret the X11 xterm mouse string
@ -641,7 +640,7 @@ void FMouseX11::setMoveState (const FPoint& mouse_position, int btn)
}
//----------------------------------------------------------------------
void FMouseX11::setButtonState (const int btn, const struct timeval* time)
void FMouseX11::setButtonState (const int btn, const TimeValue& time)
{
// Get the x11 mouse button state
@ -765,7 +764,7 @@ void FMouseSGR::setRawData (FKeyboard::keybuffer& fifo_buf)
}
//----------------------------------------------------------------------
void FMouseSGR::processEvent (struct timeval* time)
void FMouseSGR::processEvent (const TimeValue& time)
{
const auto& mouse_position = getPos();
uInt16 x{0};
@ -867,7 +866,7 @@ void FMouseSGR::setMoveState (const FPoint& mouse_position, int btn)
//----------------------------------------------------------------------
void FMouseSGR::setPressedButtonState ( const int btn
, const struct timeval* time )
, const TimeValue& time )
{
// Gets the extended x11 mouse mode (SGR) status for pressed buttons
@ -995,7 +994,7 @@ void FMouseUrxvt::setRawData (FKeyboard::keybuffer& fifo_buf)
}
//----------------------------------------------------------------------
void FMouseUrxvt::processEvent (struct timeval* time)
void FMouseUrxvt::processEvent (const TimeValue& time)
{
// Parse and interpret the X11 xterm mouse string (Urxvt-Mode)
@ -1122,7 +1121,7 @@ void FMouseUrxvt::setMoveState (const FPoint& mouse_position, int btn)
}
//----------------------------------------------------------------------
void FMouseUrxvt::setButtonState (const int btn, const struct timeval* time)
void FMouseUrxvt::setButtonState (const int btn, const TimeValue& time)
{
// Get the urxvt mouse button state
@ -1561,7 +1560,7 @@ void FMouseControl::processQueuedInput()
}
//----------------------------------------------------------------------
void FMouseControl::processEvent (struct timeval* time)
void FMouseControl::processEvent (const TimeValue& time)
{
auto mtype = getMouseWithData();
auto mouse_object = mouse_protocol[mtype].get();

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2020 Markus Gans *
* Copyright 2015-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -21,6 +21,7 @@
***********************************************************************/
#include <memory>
#include <mutex>
#include "final/fevent.h"
#include "final/fc.h"
@ -29,8 +30,17 @@
namespace finalcut
{
// static class attributes
bool FObject::timer_modify_lock;
namespace internal
{
struct var
{
static std::mutex timer_mutex;
};
std::mutex var::timer_mutex{};
} // namespace internal
//----------------------------------------------------------------------
@ -44,8 +54,6 @@ FObject::FObject (FObject* parent)
{
if ( parent ) // add object to parent
parent->addChild(this);
else
timer_modify_lock = false;
}
//----------------------------------------------------------------------
@ -179,54 +187,24 @@ bool FObject::event (FEvent* ev)
}
//----------------------------------------------------------------------
void FObject::getCurrentTime (timeval* time)
TimeValue FObject::getCurrentTime()
{
// Get the current time as timeval struct
gettimeofday(time, nullptr);
// NTP fix
while ( time->tv_usec >= 1000000 )
{
time->tv_usec -= 1000000;
time->tv_sec++;
}
while ( time->tv_usec < 0 )
{
if ( time->tv_sec > 0 )
{
time->tv_usec += 1000000;
time->tv_sec--;
}
else
{
time->tv_usec = 0;
break;
}
}
return system_clock::now(); // Get the current time
}
//----------------------------------------------------------------------
bool FObject::isTimeout (const timeval* time, uInt64 timeout)
bool FObject::isTimeout (const TimeValue& time, uInt64 timeout)
{
// Checks whether the specified time span (timeout in µs) has elapse
// Checks whether the specified time span (timeout in µs) has elapsed
struct timeval now{};
struct timeval diff{};
const auto now = getCurrentTime();
FObject::getCurrentTime(&now);
diff.tv_sec = now.tv_sec - time->tv_sec;
diff.tv_usec = now.tv_usec - time->tv_usec;
if ( now < time )
return false;
if ( diff.tv_usec < 0 )
{
diff.tv_sec--;
diff.tv_usec += 1000000;
}
const auto diff_usec = uInt64((diff.tv_sec * 1000000) + diff.tv_usec);
return ( diff_usec > timeout );
const auto diff = now - time;
const auto diff_usec = uInt64(duration_cast<microseconds>(diff).count());
return diff_usec > timeout;
}
//----------------------------------------------------------------------
@ -235,10 +213,8 @@ int FObject::addTimer (int interval)
// Create a timer and returns the timer identifier number
// (interval in ms)
timeval time_interval{};
timeval currentTime{};
int id{1};
timer_modify_lock = true;
std::lock_guard<std::mutex> lock_guard(internal::var::timer_mutex);
auto& timer_list = globalTimerList();
// find an unused timer id
@ -262,10 +238,8 @@ int FObject::addTimer (int interval)
if ( id <= 0 || id > int(timer_list->size() + 1) )
return 0;
time_interval.tv_sec = interval / 1000;
time_interval.tv_usec = (interval % 1000) * 1000;
getCurrentTime (&currentTime);
timeval timeout = currentTime + time_interval;
const auto time_interval = milliseconds(interval);
const auto timeout = getCurrentTime() + time_interval;
FTimerData t{ id, time_interval, timeout, this };
// insert in list sorted by timeout
@ -276,7 +250,6 @@ int FObject::addTimer (int interval)
++iter;
timer_list->insert (iter, t);
timer_modify_lock = false;
return id;
}
@ -288,7 +261,7 @@ bool FObject::delTimer (int id) const
if ( id <= 0 )
return false;
timer_modify_lock = true;
std::lock_guard<std::mutex> lock_guard(internal::var::timer_mutex);
auto& timer_list = globalTimerList();
auto iter = timer_list->begin();
const auto& last = timer_list->end();
@ -299,11 +272,9 @@ bool FObject::delTimer (int id) const
if ( iter != last )
{
timer_list->erase(iter);
timer_modify_lock = false;
return true;
}
timer_modify_lock = false;
return false;
}
@ -312,6 +283,7 @@ bool FObject::delOwnTimers() const
{
// Deletes all timers of this object
std::lock_guard<std::mutex> lock_guard(internal::var::timer_mutex);
auto& timer_list = globalTimerList();
if ( ! timer_list )
@ -320,7 +292,6 @@ bool FObject::delOwnTimers() const
if ( timer_list->empty() )
return false;
timer_modify_lock = true;
auto iter = timer_list->begin();
while ( iter != timer_list->end() )
@ -331,7 +302,6 @@ bool FObject::delOwnTimers() const
++iter;
}
timer_modify_lock = false;
return true;
}
@ -340,6 +310,7 @@ bool FObject::delAllTimers() const
{
// Deletes all timers of all objects
std::lock_guard<std::mutex> lock_guard(internal::var::timer_mutex);
auto& timer_list = globalTimerList();
if ( ! timer_list )
@ -348,10 +319,8 @@ bool FObject::delAllTimers() const
if ( timer_list->empty() )
return false;
timer_modify_lock = true;
timer_list->clear();
timer_list->shrink_to_fit();
timer_modify_lock = false;
return true;
}
@ -374,21 +343,19 @@ void FObject::onUserEvent (FUserEvent*)
//----------------------------------------------------------------------
uInt FObject::processTimerEvent()
{
timeval currentTime{};
uInt activated{0};
auto currentTime = getCurrentTime();
getCurrentTime (&currentTime);
if ( isTimerInUpdating() )
if ( ! internal::var::timer_mutex.try_lock() )
return 0;
auto& timer_list = globalTimerList();
if ( ! timer_list )
return 0;
if ( timer_list->empty() )
if ( ! timer_list || timer_list->empty() )
{
internal::var::timer_mutex.unlock();
return 0;
}
for (auto&& timer : *timer_list)
{
@ -402,13 +369,14 @@ uInt FObject::processTimerEvent()
if ( timer.timeout < currentTime )
timer.timeout = currentTime + timer.interval;
if ( timer.interval.tv_usec > 0 || timer.interval.tv_sec > 0 )
if ( timer.interval > microseconds(0) )
activated++;
FTimerEvent t_ev(Event::Timer, timer.id);
performTimerAction (timer.object, &t_ev);
}
internal::var::timer_mutex.unlock();
return activated;
}

View File

@ -61,14 +61,12 @@ bool FVTerm::force_terminal_update{false};
uInt64 FVTerm::flush_wait{MIN_FLUSH_WAIT};
uInt64 FVTerm::flush_average{MIN_FLUSH_WAIT};
uInt64 FVTerm::flush_median{MIN_FLUSH_WAIT};
uInt64 FVTerm::term_size_check_timeout{500000}; // 500 ms
uInt FVTerm::erase_char_length{};
uInt FVTerm::repeat_char_length{};
uInt FVTerm::clr_bol_length{};
uInt FVTerm::clr_eol_length{};
uInt FVTerm::cursor_address_length{};
struct timeval FVTerm::time_last_flush{};
struct timeval FVTerm::last_term_size_check{};
TimeValue FVTerm::time_last_flush{};
const FVTerm* FVTerm::init_object{nullptr};
FVTerm::FTermArea* FVTerm::vterm{nullptr};
FVTerm::FTermArea* FVTerm::vdesktop{nullptr};
@ -603,7 +601,7 @@ void FVTerm::flush() const
std::fflush(stdout);
auto& mouse = FTerm::getFMouseControl();
mouse.drawPointer();
FObject::getCurrentTime (&time_last_flush);
time_last_flush = FObject::getCurrentTime();
}
@ -1876,11 +1874,8 @@ void FVTerm::init()
vdesktop->visible = true;
active_area = vdesktop;
// Initialize the flush and last terminal size check time
time_last_flush.tv_sec = 0;
time_last_flush.tv_usec = 0;
last_term_size_check.tv_sec = 0;
last_term_size_check.tv_usec = 0;
// Initialize the last flush time
time_last_flush = TimeValue{};
}
//----------------------------------------------------------------------
@ -2879,33 +2874,13 @@ bool FVTerm::isInsideTerminal (const FPoint& pos) const
return false;
}
//----------------------------------------------------------------------
inline bool FVTerm::isTermSizeChanged() const
{
if ( ! isTermSizeCheckTimeout() )
return false;
FObject::getCurrentTime (&last_term_size_check);
auto& fterm_data = FTerm::getFTermData();
const auto& old_term_geometry = fterm_data.getTermGeometry();
FTerm::detectTermSize();
auto term_geometry = fterm_data.getTermGeometry();
term_geometry.move (-1, -1);
if ( old_term_geometry.getSize() != term_geometry.getSize() )
return true;
return false;
}
//----------------------------------------------------------------------
inline void FVTerm::flushTimeAdjustment() const
{
timeval now;
FObject::getCurrentTime(&now);
timeval diff = now - time_last_flush;
const auto now = FObject::getCurrentTime();
const auto diff = now - time_last_flush;
if ( diff.tv_sec > 0 || diff.tv_usec > 400000 )
if ( diff > milliseconds(400) )
{
flush_wait = MIN_FLUSH_WAIT; // Reset to minimum values after 400 ms
flush_average = MIN_FLUSH_WAIT;
@ -2913,7 +2888,7 @@ inline void FVTerm::flushTimeAdjustment() const
}
else
{
auto usec = uInt64(diff.tv_usec);
auto usec = uInt64(duration_cast<microseconds>(diff).count());
if ( usec < MIN_FLUSH_WAIT )
usec = MIN_FLUSH_WAIT;
@ -2947,13 +2922,7 @@ inline void FVTerm::flushTimeAdjustment() const
//----------------------------------------------------------------------
inline bool FVTerm::isFlushTimeout()
{
return FObject::isTimeout (&time_last_flush, flush_wait);
}
//----------------------------------------------------------------------
inline bool FVTerm::isTermSizeCheckTimeout()
{
return FObject::isTimeout (&last_term_size_check, term_size_check_timeout);
return FObject::isTimeout (time_last_flush, flush_wait);
}
//----------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2013-2020 Markus Gans *
* Copyright 2013-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -238,7 +238,7 @@ class FApplication : public FWidget
FWidget* clicked_widget{};
FEventQueue event_queue{};
static uInt64 next_event_wait;
static timeval time_last_event;
static TimeValue time_last_event;
static int loop_level;
static int quit_code;
static bool quit_now;

View File

@ -108,7 +108,7 @@ class FKeyboard final
FKey getKey() const;
FString getKeyName (const FKey) const;
keybuffer& getKeyBuffer();
timeval* getKeyPressedTime();
TimeValue getKeyPressedTime();
static uInt64 getKeypressTimeout();
static uInt64 getReadBlockingTime();
@ -179,7 +179,7 @@ class FKeyboard final
FKeyboardCommand escape_key_cmd{};
FKeyboardCommand mouse_tracking_cmd{};
static timeval time_keypressed;
static TimeValue time_keypressed;
static uInt64 read_blocking_time;
static uInt64 read_blocking_time_short;
static uInt64 key_timeout;
@ -214,8 +214,8 @@ inline FKeyboard::keybuffer& FKeyboard::getKeyBuffer()
{ return fifo_buf; }
//----------------------------------------------------------------------
inline timeval* FKeyboard::getKeyPressedTime()
{ return &time_keypressed; }
inline TimeValue FKeyboard::getKeyPressedTime()
{ return time_keypressed; }
//----------------------------------------------------------------------
inline uInt64 FKeyboard::getKeypressTimeout()

View File

@ -201,7 +201,7 @@ class FMouse : public FMouseData
template <typename ClassT>
static FMouse* createMouseObject ();
virtual void setRawData (FKeyboard::keybuffer&) = 0;
virtual void processEvent (struct timeval*) = 0;
virtual void processEvent (const TimeValue&) = 0;
protected:
// Accessors
@ -209,17 +209,17 @@ class FMouse : public FMouseData
uInt16 getMaxWidth() const;
uInt16 getMaxHeight() const;
uInt64 getDblclickInterval() const;
timeval* getMousePressedTime();
TimeValue getMousePressedTime();
// Mutator
void setNewPos (int, int);
void setPending (bool = true);
void setEvent();
void setMousePressedTime (const timeval*);
void setMousePressedTime (const TimeValue&);
void resetMousePressedTime();
// Inquiry
bool isDblclickTimeout (const timeval*) const;
bool isDblclickTimeout (const TimeValue&) const;
private:
// Data members
@ -228,7 +228,7 @@ class FMouse : public FMouseData
uInt16 max_width{80};
uInt16 max_height{25};
uInt64 dblclick_interval{500000}; // 500 ms
struct timeval time_mousepressed{};
TimeValue time_mousepressed{};
FPoint new_mouse_position{};
};
@ -263,7 +263,7 @@ class FMouseGPM final : public FMouse
// Methods
void setRawData (FKeyboard::keybuffer&) override;
void processEvent (struct timeval*) override;
void processEvent (const TimeValue&) override;
bool gpmMouse (bool = true);
bool enableGpmMouse();
bool disableGpmMouse();
@ -321,7 +321,7 @@ class FMouseX11 final : public FMouse
// Methods
void setRawData (FKeyboard::keybuffer&) override;
void processEvent (struct timeval*) override;
void processEvent (const TimeValue&) override;
private:
// Enumeration
@ -351,7 +351,7 @@ class FMouseX11 final : public FMouse
// Methods
void setKeyState (int);
void setMoveState (const FPoint&, int);
void setButtonState (const int, const struct timeval*);
void setButtonState (const int, const TimeValue&);
// Data member
char x11_mouse[MOUSE_BUF_SIZE]{'\0'};
@ -374,7 +374,7 @@ class FMouseSGR final : public FMouse
// Methods
void setRawData (FKeyboard::keybuffer&) override;
void processEvent (struct timeval*) override;
void processEvent (const TimeValue&) override;
private:
// Enumeration
@ -403,7 +403,7 @@ class FMouseSGR final : public FMouse
// Methods
void setKeyState (int);
void setMoveState (const FPoint&, int);
void setPressedButtonState (const int, const struct timeval*);
void setPressedButtonState (const int, const TimeValue&);
void setReleasedButtonState (const int);
// Data members
@ -427,7 +427,7 @@ class FMouseUrxvt final : public FMouse
// Methods
void setRawData (FKeyboard::keybuffer&) override;
void processEvent (struct timeval*) override;
void processEvent (const TimeValue&) override;
private:
// Enumeration
@ -457,7 +457,7 @@ class FMouseUrxvt final : public FMouse
// Methods
void setKeyState (int);
void setMoveState (const FPoint&, int);
void setButtonState (const int, const struct timeval*);
void setButtonState (const int, const TimeValue&);
// Data members
char urxvt_mouse[MOUSE_BUF_SIZE]{'\0'};
@ -543,7 +543,7 @@ class FMouseControl
void disable();
virtual void setRawData ( FMouse::MouseType
, FKeyboard::keybuffer& );
virtual void processEvent (struct timeval* time);
virtual void processEvent (const TimeValue&);
void processQueuedInput();
bool getGpmKeyPressed (bool = true);
void drawPointer();

View File

@ -44,15 +44,24 @@
#include <sys/time.h> // need for gettimeofday
#include <cstdlib>
#include <cstring>
#include <chrono>
#include <list>
#include <memory>
#include <vector>
#include "final/fstring.h"
#include "final/ftypes.h"
namespace finalcut
{
using std::chrono::duration_cast;
using std::chrono::seconds;
using std::chrono::milliseconds;
using std::chrono::microseconds;
using std::chrono::system_clock;
using std::chrono::time_point;
// class forward declaration
class FEvent;
class FKeyEvent;
@ -122,7 +131,6 @@ class FObject
bool isDirectChild (const FObject*) const;
bool isWidget() const;
bool isInstanceOf (const FString&) const;
bool isTimerInUpdating() const;
// Methods
void removeParent();
@ -134,8 +142,8 @@ class FObject
virtual bool event (FEvent*);
// Timer methods
static void getCurrentTime (timeval*);
static bool isTimeout (const timeval*, uInt64);
static TimeValue getCurrentTime();
static bool isTimeout (const TimeValue&, uInt64);
int addTimer (int);
bool delTimer (int) const;
bool delOwnTimers() const;
@ -145,8 +153,8 @@ class FObject
struct FTimerData
{
int id;
timeval interval;
timeval timeout;
milliseconds interval;
TimeValue timeout;
FObject* object;
};
@ -178,7 +186,6 @@ class FObject
std::size_t max_children{UNLIMITED};
bool has_parent{false};
bool widget_object{false};
static bool timer_modify_lock;
};
@ -262,10 +269,6 @@ inline bool FObject::isWidget() const
inline bool FObject::isInstanceOf (const FString& classname) const
{ return classname == getClassName(); }
//----------------------------------------------------------------------
inline bool FObject::isTimerInUpdating() const
{ return timer_modify_lock; }
//----------------------------------------------------------------------
inline FObject::FTimerList* FObject::getTimerList() const
{ return globalTimerList().get(); }
@ -274,61 +277,6 @@ inline FObject::FTimerList* FObject::getTimerList() const
inline void FObject::setWidgetProperty (bool property)
{ widget_object = property; }
//----------------------------------------------------------------------
// Operator functions for timeval
//----------------------------------------------------------------------
static inline timeval operator + (const timeval& t1, const timeval& t2)
{
timeval tmp{};
tmp.tv_sec = t1.tv_sec + t2.tv_sec;
if ( (tmp.tv_usec = t1.tv_usec + t2.tv_usec) >= 1000000 )
{
tmp.tv_sec++;
tmp.tv_usec -= 1000000;
}
return tmp;
}
//----------------------------------------------------------------------
static inline timeval operator - (const timeval& t1, const timeval& t2)
{
timeval tmp{};
tmp.tv_sec = t1.tv_sec - t2.tv_sec;
if ( (tmp.tv_usec = t1.tv_usec - t2.tv_usec) < 0 )
{
tmp.tv_sec--;
tmp.tv_usec += 1000000;
}
return tmp;
}
//----------------------------------------------------------------------
static inline timeval& operator += (timeval& t1, const timeval& t2)
{
t1.tv_sec += t2.tv_sec;
if ( (t1.tv_usec += t2.tv_usec) >= 1000000 )
{
t1.tv_sec++;
t1.tv_usec -= 1000000;
}
return t1;
}
//----------------------------------------------------------------------
static inline bool operator < (const timeval& t1, const timeval& t2)
{
return (t1.tv_sec < t2.tv_sec)
|| (t1.tv_sec == t2.tv_sec && t1.tv_usec < t2.tv_usec);
}
} // namespace finalcut
#endif // FOBJECT_H

View File

@ -34,6 +34,7 @@
#include <cstring>
#include <array>
#include <chrono>
#include <functional>
#include <limits>
#include <memory>
@ -68,7 +69,7 @@ using sInt32 = std::int32_t;
using sInt64 = std::int64_t;
using lDouble = long double;
using TimeValue = std::chrono::time_point<std::chrono::system_clock>;
using FCall = std::function<void()>;
namespace finalcut
@ -125,10 +126,10 @@ constexpr std::reverse_iterator<Iter> make_reverse_iterator (Iter iter)
return std::reverse_iterator<Iter>(iter);
}
template <typename T>
constexpr std::size_t stringLength (T&& array)
template <typename CharT>
constexpr std::size_t stringLength (const CharT* s)
{
return std::string(std::forward<T>(array)).length();
return std::char_traits<CharT>::length(s);
}
using charSubstitution = std::unordered_map<wchar_t, wchar_t>;

View File

@ -418,10 +418,8 @@ class FVTerm
bool updateTerminalLine (uInt) const;
bool updateTerminalCursor() const;
bool isInsideTerminal (const FPoint&) const;
bool isTermSizeChanged() const;
void flushTimeAdjustment() const;
static bool isFlushTimeout();
static bool isTermSizeCheckTimeout();
static bool hasPendingUpdates (const FTermArea*);
static void markAsPrinted (uInt, uInt);
static void markAsPrinted (uInt, uInt, uInt);
@ -453,8 +451,7 @@ class FVTerm
static FChar next_attribute;
static FChar s_ch; // shadow character
static FChar i_ch; // inherit background character
static timeval time_last_flush;
static timeval last_term_size_check;
static TimeValue time_last_flush;
static bool draw_completed;
static bool combined_char_support;
static bool no_terminal_updates;
@ -462,7 +459,6 @@ class FVTerm
static uInt64 flush_wait;
static uInt64 flush_average;
static uInt64 flush_median;
static uInt64 term_size_check_timeout;
static uInt erase_char_length;
static uInt repeat_char_length;
static uInt clr_bol_length;

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2018-2020 Markus Gans *
* Copyright 2018-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -373,9 +373,11 @@ void FKeyboardTest::noArgumentTest()
CPPUNIT_ASSERT ( sum == 0 );
timeval* time = keyboard->getKeyPressedTime();
CPPUNIT_ASSERT ( time->tv_sec == 0);
CPPUNIT_ASSERT ( time->tv_usec == 0);
auto time = keyboard->getKeyPressedTime();
auto duration_s = std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch());
auto duration_us = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch());
CPPUNIT_ASSERT ( duration_s.count() == 0);
CPPUNIT_ASSERT ( duration_us.count() == 0);
CPPUNIT_ASSERT ( ! keyboard->hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! keyboard->isKeyPressed() );

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2018-2020 Markus Gans *
* Copyright 2018-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -40,13 +40,13 @@ namespace test
class FMouse_protected : public finalcut::FMouse
{
public:
virtual bool hasData()
bool hasData() override
{ return true; }
virtual void setRawData (finalcut::FKeyboard::keybuffer&)
void setRawData (finalcut::FKeyboard::keybuffer&) override
{ }
virtual void processEvent (struct timeval*)
void processEvent (const TimeValue&) override
{ }
uInt16 getMaxWidth()
@ -59,7 +59,7 @@ class FMouse_protected : public finalcut::FMouse
return finalcut::FMouse::getMaxHeight();
}
const finalcut::FPoint& getNewMousePosition()
const finalcut::FPoint& getNewMousePosition() const
{
return finalcut::FMouse::getNewPos();
}
@ -69,7 +69,7 @@ class FMouse_protected : public finalcut::FMouse
return finalcut::FMouse::getDblclickInterval();
}
bool isDblclickTimeout (timeval* t)
bool isDblclickTimeout (const TimeValue& t)
{
return finalcut::FMouse::isDblclickTimeout(t);
}
@ -199,24 +199,24 @@ void FMouseTest::doubleClickTest()
test::FMouse_protected mouse;
CPPUNIT_ASSERT ( mouse.getDblclickInterval() == 500000 ); // 500 ms
timeval tv = { 0, 0 };
CPPUNIT_ASSERT ( mouse.isDblclickTimeout(&tv) );
TimeValue tv = {};
CPPUNIT_ASSERT ( mouse.isDblclickTimeout(tv) );
finalcut::FObject::getCurrentTime(&tv);
CPPUNIT_ASSERT ( ! mouse.isDblclickTimeout(&tv) );
tv = finalcut::FObject::getCurrentTime();
CPPUNIT_ASSERT ( ! mouse.isDblclickTimeout(tv) );
tv.tv_sec--; // Minus one second
CPPUNIT_ASSERT ( mouse.isDblclickTimeout(&tv) );
tv -= std::chrono::seconds(1); // Minus one second
CPPUNIT_ASSERT ( mouse.isDblclickTimeout(tv) );
mouse.setDblclickInterval(1000000);
finalcut::FObject::getCurrentTime(&tv);
CPPUNIT_ASSERT ( ! mouse.isDblclickTimeout(&tv) );
tv = finalcut::FObject::getCurrentTime();
CPPUNIT_ASSERT ( ! mouse.isDblclickTimeout(tv) );
timeval tv_delta = { 0, 500000 };
tv = tv - tv_delta;
CPPUNIT_ASSERT ( ! mouse.isDblclickTimeout(&tv) );
tv = tv - tv_delta;
CPPUNIT_ASSERT ( mouse.isDblclickTimeout(&tv) );
auto tv_delta = std::chrono::microseconds(500000);
tv -= tv_delta;
CPPUNIT_ASSERT ( ! mouse.isDblclickTimeout(tv) );
tv -= tv_delta;
CPPUNIT_ASSERT ( mouse.isDblclickTimeout(tv) );
}
//----------------------------------------------------------------------
@ -266,9 +266,8 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( std::strcmp(rawdata1, "@@") == 0 );
timeval tv;
finalcut::FObject::getCurrentTime(&tv);
x11_mouse.processEvent (&tv);
auto tv = finalcut::FObject::getCurrentTime();
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(48, 18) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -290,7 +289,7 @@ void FMouseTest::x11MouseTest()
finalcut::FKeyboard::keybuffer raw = \
{ 0x1b, '[', 'M', 0x23, 0x50, 0x32 };
x11_mouse.setRawData (raw);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasEvent() );
// Left mouse button pressed
@ -299,7 +298,7 @@ void FMouseTest::x11MouseTest()
x11_mouse.setRawData (rawdata2);
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( ! x11_mouse.hasUnprocessedInput() );
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -324,7 +323,7 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( ! x11_mouse.hasUnprocessedInput() );
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -349,8 +348,8 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( ! x11_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
x11_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -377,8 +376,8 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
x11_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -397,7 +396,7 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( ! x11_mouse.isMoved() );
x11_mouse.setRawData (rawdata5);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! x11_mouse.isMiddleButtonPressed() );
CPPUNIT_ASSERT ( x11_mouse.isMiddleButtonReleased() );
@ -410,8 +409,8 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
x11_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -430,7 +429,7 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( ! x11_mouse.isMoved() );
x11_mouse.setRawData (rawdata6);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! x11_mouse.isRightButtonPressed() );
CPPUNIT_ASSERT ( x11_mouse.isRightButtonReleased() );
@ -443,8 +442,8 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
x11_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(80, 25) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -463,7 +462,7 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( ! x11_mouse.isMoved() );
x11_mouse.setRawData (rawdata7);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( x11_mouse.isWheelDown() );
@ -476,8 +475,8 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
x11_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -496,12 +495,12 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( ! x11_mouse.isMoved() );
x11_mouse.setRawData (rawdata8);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(3, 5) );
CPPUNIT_ASSERT ( x11_mouse.isMoved() );
x11_mouse.setRawData (rawdata8);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(3, 5) );
CPPUNIT_ASSERT ( ! x11_mouse.isMoved() );
@ -515,8 +514,8 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
x11_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(16, 32) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
@ -535,21 +534,21 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( ! x11_mouse.isMoved() );
x11_mouse.setRawData (rawdata9);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( x11_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( x11_mouse.isMetaKeyPressed() );
x11_mouse.setRawData (rawdata9);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( x11_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( x11_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isMetaKeyPressed() );
x11_mouse.setRawData (rawdata9);
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( x11_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( x11_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( x11_mouse.isControlKeyPressed() );
@ -560,7 +559,7 @@ void FMouseTest::x11MouseTest()
{ 0x1b, '[', 'M', 0x20, 0x7f, 0x3f };
x11_mouse.setRawData (rawdata10);
CPPUNIT_ASSERT ( x11_mouse.hasData() );
x11_mouse.processEvent (&tv);
x11_mouse.processEvent (tv);
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
x11_mouse.clearEvent();
CPPUNIT_ASSERT ( ! x11_mouse.hasEvent() );
@ -581,9 +580,8 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( sgr_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( std::strcmp(rawdata1, "@@") == 0 );
timeval tv;
finalcut::FObject::getCurrentTime(&tv);
sgr_mouse.processEvent (&tv);
auto tv = finalcut::FObject::getCurrentTime();
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(73, 4) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
@ -605,7 +603,7 @@ void FMouseTest::sgrMouseTest()
finalcut::FKeyboard::keybuffer raw = \
{ 0x1b, '[', '<', '0', ';', '7', '3', ';', '4', 'M' };
sgr_mouse.setRawData (raw);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() );
// Left mouse button released
@ -615,7 +613,7 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( ! sgr_mouse.hasUnprocessedInput() );
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(73, 4) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
@ -640,8 +638,8 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( ! sgr_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
sgr_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(73, 4) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
@ -667,8 +665,8 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
sgr_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
@ -687,7 +685,7 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() );
sgr_mouse.setRawData (rawdata5);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMiddleButtonPressed() );
CPPUNIT_ASSERT ( sgr_mouse.isMiddleButtonReleased() );
@ -700,8 +698,8 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
sgr_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(3, 3) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
@ -720,7 +718,7 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() );
sgr_mouse.setRawData (rawdata6);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(3, 4) );
CPPUNIT_ASSERT ( ! sgr_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! sgr_mouse.isRightButtonPressed() );
@ -734,8 +732,8 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
sgr_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(4, 9) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
@ -754,7 +752,7 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() );
sgr_mouse.setRawData (rawdata7);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( sgr_mouse.isWheelDown() );
@ -767,8 +765,8 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
sgr_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(1, 2) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
@ -787,12 +785,12 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() );
sgr_mouse.setRawData (rawdata8);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(2, 3) );
CPPUNIT_ASSERT ( sgr_mouse.isMoved() );
sgr_mouse.setRawData (rawdata8);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(3, 4) );
CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() );
@ -806,8 +804,8 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
sgr_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(5, 5) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
@ -826,21 +824,21 @@ void FMouseTest::sgrMouseTest()
CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() );
sgr_mouse.setRawData (rawdata9);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( sgr_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( sgr_mouse.isMetaKeyPressed() );
sgr_mouse.setRawData (rawdata9);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( sgr_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( sgr_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMetaKeyPressed() );
sgr_mouse.setRawData (rawdata9);
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( sgr_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( sgr_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( sgr_mouse.isControlKeyPressed() );
@ -851,7 +849,7 @@ void FMouseTest::sgrMouseTest()
{ 0x1b, '[', '<', '2', ';', '1', ';', '1', 'M' };
sgr_mouse.setRawData (rawdata10);
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
sgr_mouse.clearEvent();
CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() );
@ -863,17 +861,17 @@ void FMouseTest::sgrMouseTest()
, 0x1b, '[', '<', '6', ';', '5', ';', '@', 'M', '@' };
sgr_mouse.setRawData (rawdata11);
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() );
sgr_mouse.setRawData (rawdata11);
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() );
sgr_mouse.setRawData (rawdata11);
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
sgr_mouse.processEvent (&tv);
sgr_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() );
CPPUNIT_ASSERT ( sgr_mouse.hasUnprocessedInput() );
@ -895,9 +893,8 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( urxvt_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( std::strcmp(rawdata1, "@@") == 0 );
timeval tv;
finalcut::FObject::getCurrentTime(&tv);
urxvt_mouse.processEvent (&tv);
auto tv = finalcut::FObject::getCurrentTime();
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(49, 6) );
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
CPPUNIT_ASSERT ( urxvt_mouse.isLeftButtonPressed() );
@ -918,7 +915,7 @@ void FMouseTest::urxvtMouseTest()
finalcut::FKeyboard::keybuffer raw = \
{ 0x1b, '[', '3', '2', ';', '4', '9', ';', '6', 'M' };
urxvt_mouse.setRawData (raw);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() );
// Left mouse button released
@ -928,7 +925,7 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( ! urxvt_mouse.hasUnprocessedInput() );
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(49, 6) );
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
@ -953,8 +950,8 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( ! urxvt_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
urxvt_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(49, 6) );
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
@ -980,8 +977,8 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
urxvt_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
@ -1000,7 +997,7 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() );
urxvt_mouse.setRawData (rawdata5);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! urxvt_mouse.isMiddleButtonPressed() );
CPPUNIT_ASSERT ( urxvt_mouse.isMiddleButtonReleased() );
@ -1013,8 +1010,8 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
urxvt_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(3, 3) );
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
@ -1033,7 +1030,7 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() );
urxvt_mouse.setRawData (rawdata6);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(3, 4) );
CPPUNIT_ASSERT ( ! urxvt_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! urxvt_mouse.isRightButtonPressed() );
@ -1047,8 +1044,8 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
urxvt_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(4, 9) );
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
@ -1067,7 +1064,7 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() );
urxvt_mouse.setRawData (rawdata7);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasUnprocessedInput() );
CPPUNIT_ASSERT ( urxvt_mouse.isWheelDown() );
@ -1080,8 +1077,8 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
urxvt_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(1, 2) );
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
@ -1100,12 +1097,12 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() );
urxvt_mouse.setRawData (rawdata8);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(2, 3) );
CPPUNIT_ASSERT ( urxvt_mouse.isMoved() );
urxvt_mouse.setRawData (rawdata8);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(3, 4) );
CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() );
@ -1119,8 +1116,8 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
urxvt_mouse.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(5, 5) );
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
@ -1139,21 +1136,21 @@ void FMouseTest::urxvtMouseTest()
CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() );
urxvt_mouse.setRawData (rawdata9);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( urxvt_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( ! urxvt_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( ! urxvt_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( urxvt_mouse.isMetaKeyPressed() );
urxvt_mouse.setRawData (rawdata9);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( urxvt_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( ! urxvt_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( urxvt_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( ! urxvt_mouse.isMetaKeyPressed() );
urxvt_mouse.setRawData (rawdata9);
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( urxvt_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( urxvt_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( urxvt_mouse.isControlKeyPressed() );
@ -1164,7 +1161,7 @@ void FMouseTest::urxvtMouseTest()
{ 0x1b, '[', '3', '2', ';', '1', ';', '1', 'M' };
urxvt_mouse.setRawData (rawdata10);
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() );
urxvt_mouse.clearEvent();
CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() );
@ -1176,17 +1173,17 @@ void FMouseTest::urxvtMouseTest()
, 0x1b, '[', '3', '4', ';', '5', ';', '@', 'M', '@' };
urxvt_mouse.setRawData (rawdata11);
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() );
urxvt_mouse.setRawData (rawdata11);
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() );
urxvt_mouse.setRawData (rawdata11);
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() );
CPPUNIT_ASSERT ( urxvt_mouse.hasUnprocessedInput() );
@ -1199,7 +1196,7 @@ void FMouseTest::urxvtMouseTest()
urxvt_mouse.setRawData (rawdata12);
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.hasUnprocessedInput() );
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() != finalcut::FPoint(-5, 5) );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(1, 5) );
@ -1207,7 +1204,7 @@ void FMouseTest::urxvtMouseTest()
urxvt_mouse.setRawData (rawdata12);
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() != finalcut::FPoint(3, -3) );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(3, 1) );
@ -1220,7 +1217,7 @@ void FMouseTest::urxvtMouseTest()
{ 0x1b, '[', '3', '2', ';', '7', '0', ';', '2', '5', 'M' };
urxvt_mouse.setRawData (rawdata13);
CPPUNIT_ASSERT ( urxvt_mouse.hasData() );
urxvt_mouse.processEvent (&tv);
urxvt_mouse.processEvent (tv);
CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() != finalcut::FPoint(70, 25) );
CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(40, 20) );
@ -1271,9 +1268,8 @@ void FMouseTest::mouseControlTest()
CPPUNIT_ASSERT ( mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() );
timeval tv;
finalcut::FObject::getCurrentTime(&tv);
mouse_control.processEvent (&tv);
auto tv = finalcut::FObject::getCurrentTime();
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( ! mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(5, 8) );
CPPUNIT_ASSERT ( mouse_control.hasEvent() );
@ -1293,7 +1289,7 @@ void FMouseTest::mouseControlTest()
CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() );
mouse_control.setRawData (finalcut::FMouse::MouseType::X11, rawdata1);
mouse_control.processEvent (&tv);
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( ! mouse_control.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! mouse_control.isLeftButtonPressed() );
CPPUNIT_ASSERT ( mouse_control.isLeftButtonReleased() );
@ -1306,8 +1302,8 @@ void FMouseTest::mouseControlTest()
mouse_control.setRawData (finalcut::FMouse::MouseType::Sgr, rawdata2);
CPPUNIT_ASSERT ( mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
mouse_control.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( ! mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(1, 1) );
CPPUNIT_ASSERT ( mouse_control.hasEvent() );
@ -1326,7 +1322,7 @@ void FMouseTest::mouseControlTest()
CPPUNIT_ASSERT ( ! mouse_control.isMoved() );
mouse_control.setRawData (finalcut::FMouse::MouseType::Sgr, rawdata2);
mouse_control.processEvent (&tv);
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( ! mouse_control.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! mouse_control.isMiddleButtonPressed() );
CPPUNIT_ASSERT ( mouse_control.isMiddleButtonReleased() );
@ -1337,8 +1333,8 @@ void FMouseTest::mouseControlTest()
mouse_control.setRawData (finalcut::FMouse::MouseType::Urxvt, rawdata3);
CPPUNIT_ASSERT ( mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
mouse_control.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( ! mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(3, 3) );
CPPUNIT_ASSERT ( mouse_control.hasEvent() );
@ -1357,7 +1353,7 @@ void FMouseTest::mouseControlTest()
CPPUNIT_ASSERT ( ! mouse_control.isMoved() );
mouse_control.setRawData (finalcut::FMouse::MouseType::Urxvt, rawdata3);
mouse_control.processEvent (&tv);
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(3, 4) );
CPPUNIT_ASSERT ( ! mouse_control.hasUnprocessedInput() );
CPPUNIT_ASSERT ( ! mouse_control.isRightButtonPressed() );
@ -1370,8 +1366,8 @@ void FMouseTest::mouseControlTest()
mouse_control.setRawData (finalcut::FMouse::MouseType::X11, rawdata4);
CPPUNIT_ASSERT ( mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
mouse_control.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( ! mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(80, 25) );
CPPUNIT_ASSERT ( mouse_control.hasEvent() );
@ -1390,7 +1386,7 @@ void FMouseTest::mouseControlTest()
CPPUNIT_ASSERT ( ! mouse_control.isMoved() );
mouse_control.setRawData (finalcut::FMouse::MouseType::X11, rawdata4);
mouse_control.processEvent (&tv);
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( ! mouse_control.hasUnprocessedInput() );
CPPUNIT_ASSERT ( mouse_control.isWheelDown() );
@ -1402,8 +1398,8 @@ void FMouseTest::mouseControlTest()
mouse_control.setRawData (finalcut::FMouse::MouseType::Sgr, rawdata5);
CPPUNIT_ASSERT ( mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() );
finalcut::FObject::getCurrentTime(&tv);
mouse_control.processEvent (&tv);
tv = finalcut::FObject::getCurrentTime();
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( ! mouse_control.hasData() );
CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(1, 2) );
CPPUNIT_ASSERT ( mouse_control.hasEvent() );
@ -1422,12 +1418,12 @@ void FMouseTest::mouseControlTest()
CPPUNIT_ASSERT ( ! mouse_control.isMoved() );
mouse_control.setRawData (finalcut::FMouse::MouseType::Sgr, rawdata5);
mouse_control.processEvent (&tv);
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(2, 3) );
CPPUNIT_ASSERT ( mouse_control.isMoved() );
mouse_control.setRawData (finalcut::FMouse::MouseType::Sgr, rawdata5);
mouse_control.processEvent (&tv);
mouse_control.processEvent (tv);
CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(3, 4) );
CPPUNIT_ASSERT ( ! mouse_control.isMoved() );

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2018-2020 Markus Gans *
* Copyright 2018-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -216,7 +216,6 @@ void FObjectTest::noArgumentTest()
CPPUNIT_ASSERT ( ! o1.isDirectChild(&o2) );
CPPUNIT_ASSERT ( ! o1.isWidget() );
CPPUNIT_ASSERT ( o1.isInstanceOf("FObject") );
CPPUNIT_ASSERT ( ! o1.isTimerInUpdating() );
test::FObject_protected t;
auto ev = new finalcut::FEvent(finalcut::Event::None);
@ -287,7 +286,6 @@ void FObjectTest::childObjectTest()
CPPUNIT_ASSERT ( ! c1->isDirectChild(c7) );
CPPUNIT_ASSERT ( ! c1->isWidget() );
CPPUNIT_ASSERT ( c1->isInstanceOf("FObject") );
CPPUNIT_ASSERT ( ! c1->isTimerInUpdating() );
}
//----------------------------------------------------------------------
@ -553,15 +551,16 @@ void FObjectTest::iteratorTest()
//----------------------------------------------------------------------
void FObjectTest::timeTest()
{
struct timeval time1;
TimeValue time1{};
uInt64 timeout = 750000; // 750 ms
finalcut::FObject::getCurrentTime(&time1);
CPPUNIT_ASSERT ( ! finalcut::FObject::isTimeout (&time1, timeout) );
time1 = finalcut::FObject::getCurrentTime();
CPPUNIT_ASSERT ( ! finalcut::FObject::isTimeout (time1, timeout) );
sleep(1);
CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (&time1, timeout) );
time1.tv_sec = 300;
time1.tv_usec = 2000000; // > 1000000 µs to test diff underflow
CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (&time1, timeout) );
CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (time1, timeout) );
time1 = TimeValue{}
+ std::chrono::seconds(300)
+ std::chrono::microseconds(2000000);
CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (time1, timeout) );
}
//----------------------------------------------------------------------
@ -622,19 +621,20 @@ void FObjectTest::timerTest()
CPPUNIT_ASSERT ( t1.getTimerList()->size() == 0 );
CPPUNIT_ASSERT ( t2.getTimerList()->size() == 0 );
timeval tv1 = { 1321006271, 0 };
timeval tv2 = { 27166271, 0 };
timeval tv_sum = tv1 + tv2;
CPPUNIT_ASSERT ( tv_sum.tv_sec == 1348172542 );
CPPUNIT_ASSERT ( tv_sum.tv_usec == 0 );
auto tv1 = TimeValue{} + std::chrono::seconds(1321006271);
auto tv2 = TimeValue{} + std::chrono::seconds(27166271);
auto tv2_duration = std::chrono::duration_cast<std::chrono::seconds>(tv2.time_since_epoch());
auto tv_sum = tv1 + tv2_duration;
auto sec_sum = std::chrono::duration_cast<std::chrono::seconds>(tv_sum.time_since_epoch()).count();
CPPUNIT_ASSERT ( sec_sum == 1348172542 );
timeval tv_difference = tv1 - tv2;
CPPUNIT_ASSERT ( tv_difference.tv_sec == 1293840000 );
CPPUNIT_ASSERT ( tv_difference.tv_usec == 0 );
auto tv_difference = tv1 - tv2_duration;
auto sec_difference = std::chrono::duration_cast<std::chrono::seconds>(tv_difference.time_since_epoch()).count();
CPPUNIT_ASSERT ( sec_difference == 1293840000 );
tv_sum += tv2;
CPPUNIT_ASSERT ( tv_sum.tv_sec == 1375338813 );
CPPUNIT_ASSERT ( tv_sum.tv_usec == 0 );
tv_sum += tv2_duration;
sec_sum = std::chrono::duration_cast<std::chrono::seconds>(tv_sum.time_since_epoch()).count();
CPPUNIT_ASSERT ( sec_sum == 1375338813 );
CPPUNIT_ASSERT ( tv2 < tv1 );
CPPUNIT_ASSERT ( ! (tv1 < tv2) );
@ -645,21 +645,37 @@ void FObjectTest::timerTest()
CPPUNIT_ASSERT ( tv_difference < tv_sum );
CPPUNIT_ASSERT ( ! (tv_sum < tv_difference) );
tv1.tv_usec = tv2.tv_usec = 600000;
tv_sum = tv1 + tv2;
CPPUNIT_ASSERT ( tv_sum.tv_sec == 1348172543 );
CPPUNIT_ASSERT ( tv_sum.tv_usec == 200000 );
tv1 += std::chrono::microseconds(600000);
tv2 += std::chrono::microseconds(600000);
tv2_duration = std::chrono::duration_cast<std::chrono::seconds>(tv2.time_since_epoch());
tv_sum = tv1 + tv2_duration;
auto s_sum = std::chrono::duration_cast<std::chrono::seconds>(tv_sum.time_since_epoch()).count();
CPPUNIT_ASSERT ( s_sum == 1348172542 );
auto us_sum = ( std::chrono::duration_cast<std::chrono::microseconds>(tv_sum.time_since_epoch())
- std::chrono::seconds(1348172542) ).count();
CPPUNIT_ASSERT ( us_sum == 600000 );
tv1.tv_usec = 654321;
tv2.tv_usec = 123456;
tv_difference = tv1 - tv2;
CPPUNIT_ASSERT ( tv_difference.tv_sec == 1293840000 );
CPPUNIT_ASSERT ( tv_difference.tv_usec == 530865 );
auto tv1_sec = std::chrono::duration_cast<std::chrono::seconds>(tv1.time_since_epoch());
auto tv2_sec = std::chrono::duration_cast<std::chrono::seconds>(tv2.time_since_epoch());
tv1 = TimeValue{} + tv1_sec + std::chrono::microseconds(654321);
tv2 = TimeValue{} + tv2_sec + std::chrono::microseconds(123456);
auto tv2_duration_ms = std::chrono::duration_cast<std::chrono::microseconds>(tv2.time_since_epoch());
tv_difference = tv1 - tv2_duration_ms;
sec_difference = std::chrono::duration_cast<std::chrono::seconds>(tv_difference.time_since_epoch()).count();
CPPUNIT_ASSERT ( sec_difference == 1293840000 );
auto usec_difference = ( std::chrono::duration_cast<std::chrono::microseconds>(tv_difference.time_since_epoch())
- std::chrono::seconds(1293840000) ).count();
CPPUNIT_ASSERT ( usec_difference == 530865 );
tv2.tv_usec = 999888;
tv_sum += tv2;
CPPUNIT_ASSERT ( tv_sum.tv_sec == 1375338815 );
CPPUNIT_ASSERT ( tv_sum.tv_usec == 199888 );
tv2_sec = std::chrono::duration_cast<std::chrono::seconds>(tv2.time_since_epoch());
tv2 = TimeValue{} + tv2_sec + std::chrono::microseconds(999888);
auto tv2_duration2 = std::chrono::duration_cast<std::chrono::microseconds>(tv2.time_since_epoch());
tv_sum += tv2_duration2;
s_sum = std::chrono::duration_cast<std::chrono::seconds>(tv_sum.time_since_epoch()).count();
CPPUNIT_ASSERT ( s_sum == 1375338814 );
us_sum = ( std::chrono::duration_cast<std::chrono::microseconds>(tv_sum.time_since_epoch())
- std::chrono::seconds(1375338814) ).count();
CPPUNIT_ASSERT ( us_sum == 599888 );
CPPUNIT_ASSERT ( tv2 < tv1 );
CPPUNIT_ASSERT ( ! (tv1 < tv2) );