The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

t/libmonado: Add mnd_root_get_device_brightness and mnd_root_set_device_brightness

For controlling device brightness.

Also add to Python bindings.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2426>

averyv ad36bb69 c53a6904

+105
+2
src/xrt/targets/libmonado/libmonado.def
··· 21 21 mnd_root_get_tracking_origin_count 22 22 mnd_root_get_tracking_origin_name 23 23 mnd_root_get_device_battery_status 24 + mnd_root_get_device_brightness 25 + mnd_root_set_device_brightness
+52
src/xrt/targets/libmonado/monado.c
··· 86 86 } \ 87 87 } while (false) 88 88 89 + #define CHECK_DEVICE_INDEX(INDEX) \ 90 + do { \ 91 + if (INDEX >= root->ipc_c.ism->isdev_count) { \ 92 + PE("Invalid device index (%u)", INDEX); \ 93 + return MND_ERROR_INVALID_VALUE; \ 94 + } \ 95 + } while (false) 96 + 89 97 static int 90 98 get_client_info(mnd_root_t *root, uint32_t client_id) 91 99 { ··· 313 321 switch (prop) { 314 322 case MND_PROPERTY_SUPPORTS_POSITION_BOOL: *out_bool = shared_device->supported.position_tracking; break; 315 323 case MND_PROPERTY_SUPPORTS_ORIENTATION_BOOL: *out_bool = shared_device->supported.orientation_tracking; break; 324 + case MND_PROPERTY_SUPPORTS_BRIGHTNESS_BOOL: *out_bool = shared_device->supported.brightness_control; break; 316 325 default: PE("Is not a valid boolean property (%u)", prop); return MND_ERROR_INVALID_PROPERTY; 317 326 } 318 327 ··· 600 609 default: PE("Internal error, shouldn't get here"); return MND_ERROR_OPERATION_FAILED; 601 610 } 602 611 } 612 + 613 + mnd_result_t 614 + mnd_root_get_device_brightness(mnd_root_t *root, uint32_t device_index, float *out_brightness) 615 + { 616 + CHECK_NOT_NULL(root); 617 + CHECK_DEVICE_INDEX(device_index); 618 + CHECK_NOT_NULL(out_brightness); 619 + 620 + const struct ipc_shared_device *shared_device = &root->ipc_c.ism->isdevs[device_index]; 621 + 622 + if (!shared_device->supported.brightness_control) { 623 + PE("device_get_brightness unsupported\n"); 624 + return MND_ERROR_UNSUPPORTED_OPERATION; 625 + } 626 + 627 + xrt_result_t xret = ipc_call_device_get_brightness(&root->ipc_c, device_index, out_brightness); 628 + switch (xret) { 629 + case XRT_SUCCESS: return MND_SUCCESS; 630 + case XRT_ERROR_IPC_FAILURE: PE("Connection error!"); return MND_ERROR_OPERATION_FAILED; 631 + default: PE("Internal error, shouldn't get here"); return MND_ERROR_OPERATION_FAILED; 632 + } 633 + } 634 + 635 + mnd_result_t 636 + mnd_root_set_device_brightness(mnd_root_t *root, uint32_t device_index, float brightness, bool relative) 637 + { 638 + CHECK_NOT_NULL(root); 639 + CHECK_DEVICE_INDEX(device_index); 640 + 641 + const struct ipc_shared_device *shared_device = &root->ipc_c.ism->isdevs[device_index]; 642 + 643 + if (!shared_device->supported.brightness_control) { 644 + PE("device_set_brightness unsupported\n"); 645 + return MND_ERROR_UNSUPPORTED_OPERATION; 646 + } 647 + 648 + xrt_result_t xret = ipc_call_device_set_brightness(&root->ipc_c, device_index, brightness, relative); 649 + switch (xret) { 650 + case XRT_SUCCESS: return MND_SUCCESS; 651 + case XRT_ERROR_IPC_FAILURE: PE("Connection error!"); return MND_ERROR_OPERATION_FAILED; 652 + default: PE("Internal error, shouldn't get here"); return MND_ERROR_OPERATION_FAILED; 653 + } 654 + }
+33
src/xrt/targets/libmonado/monado.h
··· 46 46 MND_ERROR_INVALID_PROPERTY = -6, 47 47 //! Supported in version 1.3 and above. 48 48 MND_ERROR_INVALID_OPERATION = -7, 49 + //! Supported in version 1.5 and above. 50 + MND_ERROR_UNSUPPORTED_OPERATION = -7, 49 51 } mnd_result_t; 50 52 51 53 /*! ··· 78 80 MND_PROPERTY_SUPPORTS_POSITION_BOOL = 3, 79 81 //! Supported in version 1.4.0 and above. 80 82 MND_PROPERTY_SUPPORTS_ORIENTATION_BOOL = 4, 83 + //! Supported in version 1.5.0 and above. 84 + MND_PROPERTY_SUPPORTS_BRIGHTNESS_BOOL = 5, 81 85 } mnd_property_t; 82 86 83 87 /*! ··· 492 496 mnd_result_t 493 497 mnd_root_get_device_battery_status( 494 498 mnd_root_t *root, uint32_t device_index, bool *out_present, bool *out_charging, float *out_charge); 499 + 500 + /*! 501 + * Get current brightness of a display device. 502 + * 503 + * @param root The libmonado state. 504 + * @param device_index Index of device to retrieve brightness from. 505 + * @param[out] out_brightness Pointer to value to populate with the current device brightness, where 0 is 0%, and 1 is 506 + * 100%. 507 + * 508 + * @return MND_SUCCESS on success 509 + */ 510 + mnd_result_t 511 + mnd_root_get_device_brightness(mnd_root_t *root, uint32_t device_index, float *out_brightness); 512 + 513 + /*! 514 + * @brief Set the display brightness. 515 + * 516 + * @param root The libmonado state. 517 + * @param device_index Index of device to retrieve battery info from. 518 + * @param[in] brightness Desired display brightness, usually between 0 and 1. Some devices may 519 + * allow exceeding 1 if the supported range exceeds 100%, but it will be clamped to 520 + * the supported range. 521 + * @param[in] relative Whether to add \a brightness to the current brightness, instead of overwriting 522 + * the current brightness. 523 + * 524 + * @return MND_SUCCESS on success 525 + */ 526 + mnd_result_t 527 + mnd_root_set_device_brightness(mnd_root_t *root, uint32_t device_index, float brightness, bool relative); 495 528 496 529 #ifdef __cplusplus 497 530 }
+18
src/xrt/targets/libmonado/monado.py
··· 72 72 self.name = name 73 73 self.serial = serial 74 74 75 + def __repr__(self): 76 + return f"{self.name} ({self.serial})" 77 + 78 + def __str__(self): 79 + return repr(self) 80 + 75 81 76 82 class Client: 77 83 def __init__(self, ident, name, primary, focused, visible, active, overlay, io_active): ··· 217 223 raise Exception(f"Could not get device role: {role_name}") 218 224 role_map[role_name] = device_int_id_ptr[0] 219 225 return role_map 226 + 227 + def get_device_brightness(self, index: int) -> float: 228 + brightness_ptr = self.ffi.new("float *") 229 + ret = self.lib.mnd_root_get_device_brightness(self.root, index, brightness_ptr) 230 + if ret != 0: 231 + raise Exception(f"get_device_brightness failed: {ret}") 232 + return brightness_ptr[0] 233 + 234 + def set_device_brightness(self, index: int, brightness: float, relative: bool) -> None: 235 + ret = self.lib.mnd_root_set_device_brightness(self.root, index, brightness, relative) 236 + if ret != 0: 237 + raise Exception(f"set_device_brightness failed: {ret}")