From 37bf3835b0b3ce7f4c80924f40735698f057ef6f Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Mon, 7 Nov 2022 06:49:40 +0100 Subject: Create class Fl_Unix_Screen_Driver used by X11 and Wayland platforms --- src/drivers/Unix/Fl_Unix_Screen_Driver.cxx | 96 ++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/drivers/Unix/Fl_Unix_Screen_Driver.cxx (limited to 'src/drivers/Unix/Fl_Unix_Screen_Driver.cxx') diff --git a/src/drivers/Unix/Fl_Unix_Screen_Driver.cxx b/src/drivers/Unix/Fl_Unix_Screen_Driver.cxx new file mode 100644 index 000000000..0b33b0a20 --- /dev/null +++ b/src/drivers/Unix/Fl_Unix_Screen_Driver.cxx @@ -0,0 +1,96 @@ +// +// Definition of the part of the Screen interface shared by X11/Wayland +// +// Copyright 2022 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + +#include +#include "Fl_Unix_Screen_Driver.H" + +fd_set Fl_Unix_Screen_Driver::fdsets[3]; +int Fl_Unix_Screen_Driver::maxfd = 0; +int Fl_Unix_Screen_Driver::nfds = 0; +Fl_Unix_Screen_Driver::FD *Fl_Unix_Screen_Driver::fd = NULL; + +// these pointers are set by the Fl::lock() function: +static void nothing() {} +void (*fl_lock_function)() = nothing; +void (*fl_unlock_function)() = nothing; + + +// This is never called with time_to_wait < 0.0: +// It should return negative on error, 0 if nothing happens before +// timeout, and >0 if any callbacks were done. +int Fl_Unix_Screen_Driver::poll_or_select_with_delay(double time_to_wait) { +# if !USE_POLL + fd_set fdt[3]; + fdt[0] = fdsets[0]; + fdt[1] = fdsets[1]; + fdt[2] = fdsets[2]; +# endif + int n; + + fl_unlock_function(); + + if (time_to_wait < 2147483.648) { +# if USE_POLL + n = ::poll(pollfds, nfds, int(time_to_wait*1000 + .5)); +# else + timeval t; + t.tv_sec = int(time_to_wait); + t.tv_usec = int(1000000 * (time_to_wait-t.tv_sec)); + n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t); +# endif + } else { +# if USE_POLL + n = ::poll(pollfds, nfds, -1); +# else + n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],0); +# endif + } + + fl_lock_function(); + + if (n > 0) { + for (int i=0; i