summaryrefslogtreecommitdiff
path: root/src/common/desktop.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-14 13:13:52 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-14 13:13:52 +0300
commit1ab3e5a123109704789c2768e11a4f9af515821d (patch)
tree31ee03e58093a58100c6eb58681d5d29648a5ddd /src/common/desktop.c
parentd86fa6215d40caa7852dbbd6a8cf4aa8e89dd879 (diff)
Redefine public and rendering APIs with explicit contracts
Diffstat (limited to 'src/common/desktop.c')
-rw-r--r--src/common/desktop.c106
1 files changed, 86 insertions, 20 deletions
diff --git a/src/common/desktop.c b/src/common/desktop.c
index 5045604..a9f72e3 100644
--- a/src/common/desktop.c
+++ b/src/common/desktop.c
@@ -11,17 +11,20 @@
static bool uri_valid(const char *uri)
{
unsigned char c = (unsigned char)uri[0];
- if ((unsigned)((c | 32) - 'a') >= 26) return false;
+ if ((unsigned)((c | 32) - 'a') >= 26)
+ return false;
const char *p = uri + 1;
for (; *p != ':'; p++) {
c = (unsigned char)*p;
bool alpha = (unsigned)((c | 32) - 'a') < 26;
bool digit = (unsigned)(c - '0') < 10;
- if (!alpha && !digit && c != '+' && c != '-' && c != '.') return false;
+ if (!alpha && !digit && c != '+' && c != '-' && c != '.')
+ return false;
}
for (; *p; p++) {
c = (unsigned char)*p;
- if (c < 0x20 || c == 0x7f) return false;
+ if (c < 0x20 || c == 0x7f)
+ return false;
}
return true;
}
@@ -38,13 +41,16 @@ static size_t copy_out(char *out, size_t cap, const char *s, size_t len)
bool yasl_private_display_open_uri(struct yasl_private_display *d, const char *uri)
{
- if (!d || !uri || !uri_valid(uri)) return false;
+ if (!d || !uri || !uri_valid(uri))
+ return false;
return desktop_open_uri(uri);
}
-bool yasl_private_display_notify(struct yasl_private_display *d, const char *title, const char *body)
+bool yasl_private_display_notify(struct yasl_private_display *d, const char *title,
+ const char *body)
{
- if (!d || !title) return false;
+ if (!d || !title)
+ return false;
return desktop_notify(d->app_id, title, body ? body : "");
}
@@ -55,27 +61,31 @@ uint32_t yasl_private_display_appearance(struct yasl_private_display *d)
bool yasl_private_surface_bell(struct yasl_surface *s)
{
- if (!s || !s->display->ops->surface_bell) return false;
+ if (!s || !s->display->ops->surface_bell)
+ return false;
return s->display->ops->surface_bell(s);
}
size_t yasl_private_executable_path(char *out, size_t cap)
{
- if (!out && cap) return 0;
+ if (!out && cap)
+ return 0;
char buf[DESKTOP_STR_MAX];
return copy_out(out, cap, buf, desktop_executable_path(buf, sizeof(buf)));
}
size_t yasl_private_resource_dir(char *out, size_t cap)
{
- if (!out && cap) return 0;
+ if (!out && cap)
+ return 0;
char buf[DESKTOP_STR_MAX];
return copy_out(out, cap, buf, desktop_resource_dir(buf, sizeof(buf)));
}
size_t yasl_private_default_locale(char *out, size_t cap)
{
- if (!out && cap) return 0;
+ if (!out && cap)
+ return 0;
char buf[DESKTOP_STR_MAX];
return copy_out(out, cap, buf, desktop_default_locale(buf, sizeof(buf)));
}
@@ -83,13 +93,69 @@ size_t yasl_private_default_locale(char *out, size_t cap)
#include "public_internal.h"
#include "yasl/desktop.h"
#include <errno.h>
-bool yasl_open_uri(const char *uri)
-{ if(!uri||!uri_valid(uri))return yasl_public_fail(EINVAL);errno=0;return desktop_open_uri(uri)||yasl_public_fail(errno); }
-bool yasl_notify(const char *title,const char *body)
-{ if(!yasl_public_owner())return false;errno=0;return yasl_private_display_notify(yasl_public_display(),title,body)||yasl_public_fail(errno); }
-unsigned yasl_appearance(void) { return yasl_private_display_appearance(yasl_public_display()); }
-bool yasl_surface_bell(yasl_surface *s)
-{ if(!yasl_public_surface(s,false))return false;errno=0;return yasl_private_surface_bell(s)||yasl_public_fail(errno); }
-size_t yasl_executable_path(char *out,size_t cap) { return yasl_private_executable_path(out,cap); }
-size_t yasl_resource_dir(char *out,size_t cap) { return yasl_private_resource_dir(out,cap); }
-size_t yasl_default_locale(char *out,size_t cap) { return yasl_private_default_locale(out,cap); }
+int yasl_open_uri(const char *uri)
+{
+ if (!uri || !uri_valid(uri))
+ return yasl_public_error(EINVAL);
+ errno = 0;
+ return yasl_public_status(desktop_open_uri(uri) || yasl_public_fail(errno));
+}
+int yasl_notify(const char *title, const char *body)
+{
+ if (!yasl_public_owner())
+ return -errno;
+ if (!title)
+ return yasl_public_error(EINVAL);
+ errno = 0;
+ return yasl_public_status(yasl_private_display_notify(yasl_public_display(), title, body) ||
+ yasl_public_fail(errno));
+}
+unsigned yasl_get_appearance(void)
+{
+ return yasl_public_owner() ? yasl_private_display_appearance(yasl_public_display()) : 0;
+}
+int yasl_surface_bell(yasl_surface *s)
+{
+ if (!yasl_public_surface(s, false))
+ return -errno;
+ if (!s->display->ops->surface_bell)
+ return yasl_public_error(ENOTSUP);
+ errno = 0;
+ return yasl_public_status(yasl_private_surface_bell(s) || yasl_public_fail(errno));
+}
+size_t yasl_get_executable_path(char *out, size_t cap)
+{
+ if (!out && cap) {
+ yasl_public_fail(EINVAL);
+ return 0;
+ }
+ errno = 0;
+ size_t n = yasl_private_executable_path(out, cap);
+ if (!n)
+ yasl_public_fail(errno);
+ return n;
+}
+size_t yasl_get_resource_dir(char *out, size_t cap)
+{
+ if (!out && cap) {
+ yasl_public_fail(EINVAL);
+ return 0;
+ }
+ errno = 0;
+ size_t n = yasl_private_resource_dir(out, cap);
+ if (!n)
+ yasl_public_fail(errno);
+ return n;
+}
+size_t yasl_get_default_locale(char *out, size_t cap)
+{
+ if (!out && cap) {
+ yasl_public_fail(EINVAL);
+ return 0;
+ }
+ errno = 0;
+ size_t n = yasl_private_default_locale(out, cap);
+ if (!n)
+ yasl_public_fail(errno);
+ return n;
+}