mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 09:21:28 +00:00
common/util: fix get_current_time_msec
returning microseconds
This commit makes `get_current_time_msec` correctly return milliseconds as opposed to microseconds. It also considers the value of `tv_sec`, so we don't lose occasionally go back in time by one second. Finally, the function is moved into `util.c` so that it can be reused elsewhere without having to consider these pitfalls.
This commit is contained in:
parent
d835df38de
commit
d7900c6e5e
|
@ -1,8 +1,8 @@
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <float.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
@ -10,6 +10,12 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
uint32_t get_current_time_msec(void) {
|
||||||
|
struct timespec now;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
return now.tv_sec * 1000 + now.tv_nsec / 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
int wrap(int i, int max) {
|
int wrap(int i, int max) {
|
||||||
return ((i % max) + max) % max;
|
return ((i % max) + max) % max;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,13 @@
|
||||||
#include <wayland-server-protocol.h>
|
#include <wayland-server-protocol.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap i into the range [0, max[
|
* Get the current time, in milliseconds.
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32_t get_current_time_msec(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap i into the range [0, max]
|
||||||
*/
|
*/
|
||||||
int wrap(int i, int max);
|
int wrap(int i, int max);
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
#include <libevdev/libevdev.h>
|
#include <libevdev/libevdev.h>
|
||||||
#include <linux/input-event-codes.h>
|
#include <linux/input-event-codes.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <float.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <wlr/types/wlr_box.h>
|
#include <wlr/types/wlr_box.h>
|
||||||
#include <wlr/types/wlr_cursor.h>
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
@ -13,9 +11,9 @@
|
||||||
#include <wlr/types/wlr_tablet_v2.h>
|
#include <wlr/types/wlr_tablet_v2.h>
|
||||||
#include <wlr/types/wlr_xcursor_manager.h>
|
#include <wlr/types/wlr_xcursor_manager.h>
|
||||||
#include <wlr/util/region.h>
|
#include <wlr/util/region.h>
|
||||||
#include "list.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "sway/desktop.h"
|
#include "sway/desktop.h"
|
||||||
#include "sway/desktop/transaction.h"
|
#include "sway/desktop/transaction.h"
|
||||||
|
@ -24,19 +22,12 @@
|
||||||
#include "sway/input/tablet.h"
|
#include "sway/input/tablet.h"
|
||||||
#include "sway/layers.h"
|
#include "sway/layers.h"
|
||||||
#include "sway/output.h"
|
#include "sway/output.h"
|
||||||
#include "sway/tree/arrange.h"
|
|
||||||
#include "sway/tree/container.h"
|
#include "sway/tree/container.h"
|
||||||
#include "sway/tree/root.h"
|
#include "sway/tree/root.h"
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
#include "sway/tree/workspace.h"
|
#include "sway/tree/workspace.h"
|
||||||
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
||||||
|
|
||||||
static uint32_t get_current_time_msec(void) {
|
|
||||||
struct timespec now;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
||||||
return now.tv_nsec / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_surface *layer_surface_at(struct sway_output *output,
|
static struct wlr_surface *layer_surface_at(struct sway_output *output,
|
||||||
struct wl_list *layer, double ox, double oy, double *sx, double *sy) {
|
struct wl_list *layer, double ox, double oy, double *sx, double *sy) {
|
||||||
struct sway_layer_surface *sway_layer;
|
struct sway_layer_surface *sway_layer;
|
||||||
|
|
Loading…
Reference in a new issue