uterm_video: add callback
Allow applications to register callback and notify them about new or gone displays. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
1 parent
c04c807eca
commit
e6db44385b
4 files changed
+54
-1
No files matched your search
+17
@@ -117,6 +117,20 @@ enum uterm_video_type {
|
||||
UTERM_VIDEO_FBDEV,
|
||||
};
|
||||
|
||||
enum uterm_video_action {
|
||||
UTERM_NEW,
|
||||
UTERM_GONE,
|
||||
};
|
||||
|
||||
struct uterm_video_hotplug {
|
||||
struct uterm_display *display;
|
||||
int action;
|
||||
};
|
||||
|
||||
typedef void (*uterm_video_cb) (struct uterm_video *video,
|
||||
struct uterm_video_hotplug *arg,
|
||||
void *data);
|
||||
|
||||
/* misc */
|
||||
|
||||
const char *uterm_dpms_to_name(int dpms);
|
||||
@@ -170,6 +184,9 @@ void uterm_video_unref(struct uterm_video *video);
|
||||
|
||||
void uterm_video_segfault(struct uterm_video *video);
|
||||
struct uterm_display *uterm_video_get_displays(struct uterm_video *video);
|
||||
int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb,
|
||||
void *data);
|
||||
void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb);
|
||||
|
||||
void uterm_video_sleep(struct uterm_video *video);
|
||||
int uterm_video_wake_up(struct uterm_video *video);
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include "eloop.h"
|
||||
#include "misc.h"
|
||||
#include "uterm.h"
|
||||
|
||||
/* backend-operations */
|
||||
@@ -262,6 +263,7 @@ struct uterm_video {
|
||||
struct ev_fd *umon_fd;
|
||||
|
||||
struct uterm_display *displays;
|
||||
struct kmscon_hook *hook;
|
||||
|
||||
const struct video_ops *ops;
|
||||
union {
|
||||
@@ -280,4 +282,10 @@ static inline bool video_need_hotplug(const struct uterm_video *video)
|
||||
return video->flags & VIDEO_HOTPLUG;
|
||||
}
|
||||
|
||||
#define VIDEO_CB(vid, disp, act) kmscon_hook_call((vid)->hook, (vid), \
|
||||
&(struct uterm_video_hotplug){ \
|
||||
.display = (disp), \
|
||||
.action = (act), \
|
||||
})
|
||||
|
||||
#endif /* UTERM_INTERNAL_H */
|
||||
+26
-1
@@ -38,6 +38,7 @@
|
||||
#include <unistd.h>
|
||||
#include "eloop.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
#include "uterm.h"
|
||||
#include "uterm_internal.h"
|
||||
|
||||
@@ -423,11 +424,15 @@ int uterm_video_new(struct uterm_video **out,
|
||||
video->ops = ops;
|
||||
video->eloop = eloop;
|
||||
|
||||
ret = kmscon_hook_new(&video->hook);
|
||||
if (ret)
|
||||
goto err_free;
|
||||
|
||||
video->udev = udev_new();
|
||||
if (!video->udev) {
|
||||
log_err("cannot create udev object");
|
||||
ret = -EFAULT;
|
||||
goto err_free;
|
||||
goto err_hook;
|
||||
}
|
||||
|
||||
video->umon = udev_monitor_new_from_netlink(video->udev, "udev");
|
||||
@@ -464,6 +469,8 @@ err_umon:
|
||||
udev_monitor_unref(video->umon);
|
||||
err_udev:
|
||||
udev_unref(video->udev);
|
||||
err_hook:
|
||||
kmscon_hook_free(video->hook);
|
||||
err_free:
|
||||
free(video);
|
||||
return ret;
|
||||
@@ -497,6 +504,7 @@ void uterm_video_unref(struct uterm_video *video)
|
||||
ev_eloop_rm_fd(video->umon_fd);
|
||||
udev_monitor_unref(video->umon);
|
||||
udev_unref(video->udev);
|
||||
kmscon_hook_free(video->hook);
|
||||
ev_eloop_unref(video->eloop);
|
||||
free(video);
|
||||
__sync_fetch_and_sub(&video_protect, 1);
|
||||
@@ -518,6 +526,23 @@ struct uterm_display *uterm_video_get_displays(struct uterm_video *video)
|
||||
return video->displays;
|
||||
}
|
||||
|
||||
int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb,
|
||||
void *data)
|
||||
{
|
||||
if (!video || !cb)
|
||||
return -EINVAL;
|
||||
|
||||
return kmscon_hook_add_cast(video->hook, cb, data);
|
||||
}
|
||||
|
||||
void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb)
|
||||
{
|
||||
if (!video || !cb)
|
||||
return;
|
||||
|
||||
kmscon_hook_rm_cast(video->hook, cb);
|
||||
}
|
||||
|
||||
void uterm_video_sleep(struct uterm_video *video)
|
||||
{
|
||||
if (!video || !video_is_awake(video))
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
/* #include <xf86drmMode.h> TODO: missing header protection */
|
||||
#include "eloop.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
#include "uterm.h"
|
||||
#include "uterm_internal.h"
|
||||
|
||||
@@ -460,6 +461,7 @@ static void bind_display(struct uterm_video *video, drmModeRes *res,
|
||||
disp->dpms = get_dpms(disp, conn);
|
||||
log_info("display %p DPMS is %s", disp,
|
||||
uterm_dpms_to_name(disp->dpms));
|
||||
VIDEO_CB(video, disp, UTERM_NEW);
|
||||
}
|
||||
|
||||
static void unbind_display(struct uterm_display *disp)
|
||||
@@ -467,6 +469,7 @@ static void unbind_display(struct uterm_display *disp)
|
||||
if (!display_is_conn(disp))
|
||||
return;
|
||||
|
||||
VIDEO_CB(disp->video, disp, UTERM_GONE);
|
||||
display_deactivate(disp);
|
||||
disp->video = NULL;
|
||||
disp->flags &= ~DISPLAY_AVAILABLE;
|
||||
|
||||
Reference in new issue
Block a user