expand IntervalTimer, more clipboard fixes
This commit is contained in:
parent
83dd2f6039
commit
09cd7a1fd7
20
platform.d
20
platform.d
@ -528,6 +528,7 @@ struct PlatformWindow
|
||||
Inputs[2] inputs;
|
||||
TicketMut input_mutex;
|
||||
|
||||
IntervalTimer cb_timer;
|
||||
TicketMut cb_mut;
|
||||
Selection[CBM.max] selections;
|
||||
version(linux) u32 cb_transfer_size;
|
||||
@ -567,6 +568,7 @@ CreateWindow(string name, u16 width, u16 height)
|
||||
input_mutex: CreateTicketMut(),
|
||||
msg_queue: CreateMessageQueue(),
|
||||
cb_mut: CreateTicketMut(),
|
||||
cb_timer: CreateTimer(X11_TIMEOUT_DEFAULT),
|
||||
inputs: [
|
||||
{ arena: CreateArena(MB(1)) },
|
||||
{ arena: CreateArena(MB(1)) },
|
||||
@ -882,10 +884,6 @@ ClipboardText(PlatformWindow* w, ClipboardMode mode)
|
||||
}
|
||||
else
|
||||
{
|
||||
timeval now;
|
||||
timespec timeout;
|
||||
int pret = 0;
|
||||
|
||||
auto owner = xcb_get_selection_owner_reply(w.conn, xcb_get_selection_owner(w.conn, sel.xmode), null);
|
||||
scope(exit) pureFree(owner);
|
||||
|
||||
@ -898,18 +896,8 @@ ClipboardText(PlatformWindow* w, ClipboardMode mode)
|
||||
xcb_convert_selection(w.conn, w.window, sel.xmode, sel.target, sel.xmode, XCB_CURRENT_TIME);
|
||||
xcb_flush(w.conn);
|
||||
|
||||
gettimeofday(&now, null);
|
||||
|
||||
timeout.tv_sec = now.tv_sec + (X11_TIMEOUT_DEFAULT / 1000);
|
||||
timeout.tv_nsec = (now.tv_usec * 1000UL) * ((X11_TIMEOUT_DEFAULT % 1000) * 1000000UL);
|
||||
if(timeout.tv_nsec >= 1000000000UL)
|
||||
{
|
||||
timeout.tv_sec += timeout.tv_nsec / 1000000000UL;
|
||||
timeout.tv_nsec = timeout.tv_nsec % 1000000000UL;
|
||||
}
|
||||
|
||||
Lock(&w.cb_mut);
|
||||
Unlock(&w.cb_mut);
|
||||
ResetTimer(&w.cb_timer);
|
||||
while(!CheckTimer(&w.cb_timer) && sel.data.length == 0) {}
|
||||
|
||||
GetClipboardSelection(w, sel);
|
||||
}
|
||||
|
||||
16
util.d
16
util.d
@ -709,7 +709,13 @@ struct IntervalTimer
|
||||
}
|
||||
|
||||
IntervalTimer
|
||||
CreateTimer(u64 fps)
|
||||
CreateFPSTimer(u64 fps)
|
||||
{
|
||||
return CreateTimer(1000/fps);
|
||||
}
|
||||
|
||||
IntervalTimer
|
||||
CreateTimer(u64 ms)
|
||||
{
|
||||
IntervalTimer timer;
|
||||
|
||||
@ -738,12 +744,18 @@ CreateTimer(u64 fps)
|
||||
}
|
||||
|
||||
timer.cpu_freq = cpu_freq;
|
||||
timer.interval = cpu_freq/(fps+1);
|
||||
timer.interval = cpu_freq*(ms/1000);
|
||||
timer.prev = RDTSC();
|
||||
|
||||
return timer;
|
||||
}
|
||||
|
||||
void
|
||||
ResetTimer(IntervalTimer* t)
|
||||
{
|
||||
t.prev = RDTSC();
|
||||
}
|
||||
|
||||
pragma(inline) bool
|
||||
CheckTimer(IntervalTimer* t)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user