Skip to content

Commit

Permalink
Added a new WebcamChanged bus signal that will let clients know when …
Browse files Browse the repository at this point in the history
…a new webcam is connected/a webcam is disconnected from system.
  • Loading branch information
FedeDP committed Sep 12, 2018
1 parent 536859d commit 935ab3a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Last line will smoothly change current backlight on every internal/external scre

Please note that for internal laptop screen, serialNumber must be your backlight kernel interface (eg: intel_backlight) or an empty string (to forcefully use first udev backlight subsystem matching device).

A "version" bus property is exported too. It will return a "s" of clightd version.
### Methods

*Smooth struct* here means:
* b -> isSmooth (true for smooth change)
Expand All @@ -112,6 +112,19 @@ A "version" bus property is exported too. It will return a "s" of clightd versio
| setdpms_timeouts | ssiii | <ul><li>env DISPLAY</li><li>env XAUTHORITY</li><li>New dpms timeouts</li></ul> | iii | New dpms timeouts |||
| getidletime | ss | <ul><li>env DISPLAY</li><li>env XAUTHORITY</li></ul> | i | Current idle time in ms | ||

### Properties

| Prop | OUT | OUT values |
|-|:-:|-|
| version | s | Clightd version |

### Signals

| Sig | OUT | OUT values |
|-|:-:|-|
| WebcamChanged | ss | <ul><li>Webcam's devpath</li><li>Action string, as received from udev. Eg: "add", "remove".</li></ul> |


## Ddcutil support
Clightd uses [ddcutil](https://github.com/rockowitz/ddcutil) C api to set external monitor brightness and thus supporting desktop PCs too.

Expand Down
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 2.4
- [x] Add WebcamChanged signal that will be sent when a new webcam is connected/a webcam is disconnected

## 2.5
- [ ] Add gamma (and dpms + idle) support on wayland (wlroots)
https://github.com/swaywm/wlroots/blob/master/examples/gamma-control.c
https://github.com/swaywm/wlroots/blob/master/examples/idle.c
Expand Down
4 changes: 4 additions & 0 deletions inc/udev.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

extern struct udev *udev;

#ifndef DISABLE_FRAME_CAPTURES
int init_udev_monitor(const char *subsystem);
void receive_udev_device(struct udev_device **dev);
#endif
void get_udev_device(const char *interface, const char *subsystem,
sd_bus_error **ret_error, struct udev_device **dev);
21 changes: 21 additions & 0 deletions src/clightd.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ enum poll_idx {
BRIGHT_SMOOTH,
#ifdef GAMMA_PRESENT
GAMMA_SMOOTH,
#endif
#ifndef DISABLE_FRAME_CAPTURES
UDEV_MON,
#endif
POLL_SIZE };
enum quit_codes { LEAVE_W_ERR = -1, SIGNAL_RCV = 1 };
Expand Down Expand Up @@ -74,6 +77,7 @@ static const sd_bus_vtable clightd_vtable[] = {
#ifndef DISABLE_FRAME_CAPTURES
SD_BUS_METHOD("captureframes", "si", "ad", method_captureframes, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("iswebcamavailable", "", "b", method_iswebcamavailable, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_SIGNAL("WebcamChanged", "ss", 0),
#endif
#ifdef DPMS_PRESENT
SD_BUS_METHOD("getdpms", "ss", "i", method_getdpms, SD_BUS_VTABLE_UNPRIVILEGED),
Expand Down Expand Up @@ -151,6 +155,12 @@ static void set_pollfd(void) {
};
set_gamma_smooth_fd(gamma_smooth_fd);
#endif
#ifndef DISABLE_FRAME_CAPTURES
main_p[UDEV_MON] = (struct pollfd) {
.fd = init_udev_monitor("video4linux"),
.events = POLLIN,
};
#endif
}

/*
Expand Down Expand Up @@ -181,6 +191,17 @@ static void main_poll(void) {
case GAMMA_SMOOTH:
gamma_smooth_cb();
break;
#endif
#ifndef DISABLE_FRAME_CAPTURES
case UDEV_MON: {
struct udev_device *dev = NULL;
receive_udev_device(&dev);
if (dev) {
sd_bus_emit_signal(bus, object_path, bus_interface, "WebcamChanged", "ss", udev_device_get_devnode(dev), udev_device_get_action(dev));
udev_device_unref(dev);
}
break;
}
#endif
}
r--;
Expand Down
15 changes: 15 additions & 0 deletions src/udev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

static void get_first_matching_device(struct udev_device **dev, const char *subsystem);

#ifndef DISABLE_FRAME_CAPTURES
static struct udev_monitor *mon;

int init_udev_monitor(const char *subsystem) {
mon = udev_monitor_new_from_netlink(udev, "udev");
udev_monitor_filter_add_match_subsystem_devtype(mon, subsystem, NULL);
udev_monitor_enable_receiving(mon);
return udev_monitor_get_fd(mon);
}

void receive_udev_device(struct udev_device **dev) {
*dev = udev_monitor_receive_device(mon);
}
#endif

/**
* Set dev to first device in subsystem
*/
Expand Down

0 comments on commit 935ab3a

Please sign in to comment.