Compare commits
6 Commits
0f20cce9c8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
7566f9af82
|
|||
|
7425355d01
|
|||
|
d8f785eae5
|
|||
|
31ae400852
|
|||
|
b69d3f8692
|
|||
|
9a26284a64
|
@@ -86,24 +86,30 @@ xdg_xsettings_update (struct xdg_xsettings *self, Display *dpy)
|
|||||||
// TODO: We're supposed to lock the server.
|
// TODO: We're supposed to lock the server.
|
||||||
// TODO: We're supposed to trap X errors.
|
// TODO: We're supposed to trap X errors.
|
||||||
char *selection = xstrdup_printf ("_XSETTINGS_S%d", DefaultScreen (dpy));
|
char *selection = xstrdup_printf ("_XSETTINGS_S%d", DefaultScreen (dpy));
|
||||||
Window owner
|
Atom selection_atom = XInternAtom (dpy, selection, True);
|
||||||
= XGetSelectionOwner (dpy, XInternAtom (dpy, selection, True));
|
|
||||||
free (selection);
|
free (selection);
|
||||||
|
if (!selection_atom)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Window owner = XGetSelectionOwner (dpy, selection_atom);
|
||||||
if (!owner)
|
if (!owner)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Atom xsettings_atom = XInternAtom (dpy, "_XSETTINGS_SETTINGS", True);
|
||||||
|
if (!xsettings_atom)
|
||||||
|
return;
|
||||||
|
|
||||||
Atom actual_type = None;
|
Atom actual_type = None;
|
||||||
int actual_format = 0;
|
int actual_format = 0;
|
||||||
unsigned long nitems = 0, bytes_after = 0;
|
unsigned long nitems = 0, bytes_after = 0;
|
||||||
unsigned char *buffer = NULL;
|
unsigned char *buffer = NULL;
|
||||||
Atom xsettings = XInternAtom (dpy, "_XSETTINGS_SETTINGS", True);
|
|
||||||
int status = XGetWindowProperty (dpy,
|
int status = XGetWindowProperty (dpy,
|
||||||
owner,
|
owner,
|
||||||
xsettings,
|
xsettings_atom,
|
||||||
0L,
|
0L,
|
||||||
LONG_MAX,
|
LONG_MAX,
|
||||||
False,
|
False,
|
||||||
xsettings,
|
xsettings_atom,
|
||||||
&actual_type,
|
&actual_type,
|
||||||
&actual_format,
|
&actual_format,
|
||||||
&nitems,
|
&nitems,
|
||||||
@@ -112,7 +118,7 @@ xdg_xsettings_update (struct xdg_xsettings *self, Display *dpy)
|
|||||||
if (status != Success || !buffer)
|
if (status != Success || !buffer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (actual_type != xsettings
|
if (actual_type != xsettings_atom
|
||||||
|| actual_format != 8
|
|| actual_format != 8
|
||||||
|| nitems < 12)
|
|| nitems < 12)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|||||||
@@ -1884,6 +1884,8 @@ x11_init (struct poller *poller, struct attrs *app_attrs, size_t app_attrs_len)
|
|||||||
if (!(g_xui.dpy = XkbOpenDisplay
|
if (!(g_xui.dpy = XkbOpenDisplay
|
||||||
(NULL, &g_xui.xkb_base_event_code, NULL, NULL, NULL, NULL)))
|
(NULL, &g_xui.xkb_base_event_code, NULL, NULL, NULL, NULL)))
|
||||||
exit_fatal ("cannot open display");
|
exit_fatal ("cannot open display");
|
||||||
|
if (!XftInit (NULL))
|
||||||
|
print_warning ("Fontconfig initialization failed");
|
||||||
if (!XftDefaultHasRender (g_xui.dpy))
|
if (!XftDefaultHasRender (g_xui.dpy))
|
||||||
exit_fatal ("XRender is not supported");
|
exit_fatal ("XRender is not supported");
|
||||||
if (!(g_xui.x11_im = XOpenIM (g_xui.dpy, NULL, NULL, NULL)))
|
if (!(g_xui.x11_im = XOpenIM (g_xui.dpy, NULL, NULL, NULL)))
|
||||||
@@ -1912,8 +1914,6 @@ x11_init (struct poller *poller, struct attrs *app_attrs, size_t app_attrs_len)
|
|||||||
g_xui.x11_xsettings = xdg_xsettings_make ();
|
g_xui.x11_xsettings = xdg_xsettings_make ();
|
||||||
xdg_xsettings_update (&g_xui.x11_xsettings, g_xui.dpy);
|
xdg_xsettings_update (&g_xui.x11_xsettings, g_xui.dpy);
|
||||||
|
|
||||||
if (!FcInit ())
|
|
||||||
print_warning ("Fontconfig initialization failed");
|
|
||||||
if (!(g_xui.xft_fonts = x11_font_open (0)))
|
if (!(g_xui.xft_fonts = x11_font_open (0)))
|
||||||
exit_fatal ("cannot open a font");
|
exit_fatal ("cannot open a font");
|
||||||
|
|
||||||
|
|||||||
@@ -1209,7 +1209,10 @@ async_make (struct async_manager *manager)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Only allowed from the main thread once the job has been started but before
|
/// Only allowed from the main thread once the job has been started but before
|
||||||
/// the results have been dispatched
|
/// the results have been dispatched.
|
||||||
|
///
|
||||||
|
/// Note that it may in practice lead to memory leakage, although that's
|
||||||
|
/// an implementation issue: https://eissing.org/icing/posts/rip_pthread_cancel/
|
||||||
static void
|
static void
|
||||||
async_cancel (struct async *self)
|
async_cancel (struct async *self)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -93,10 +93,12 @@ and always-present field, which must be a tag *enum*:
|
|||||||
case CAR: void;
|
case CAR: void;
|
||||||
case LORRY: i8 axles;
|
case LORRY: i8 axles;
|
||||||
case PLANE: i8 engines;
|
case PLANE: i8 engines;
|
||||||
|
default: void;
|
||||||
};
|
};
|
||||||
|
|
||||||
All possible enumeration values must be named, and there is no *case*
|
There is no *case* fall-through.
|
||||||
fall-through.
|
Unless *default* is present, only the listed enumeration values are valid.
|
||||||
|
Any *default* must currently be empty.
|
||||||
|
|
||||||
Framing
|
Framing
|
||||||
-------
|
-------
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ syn region libertyxdrBlockComment start=+/[*]+ end=+[*]/+
|
|||||||
syn match libertyxdrComment "//.*"
|
syn match libertyxdrComment "//.*"
|
||||||
syn match libertyxdrIdentifier "\<[[:alpha:]][[:alnum:]_]*\>"
|
syn match libertyxdrIdentifier "\<[[:alpha:]][[:alnum:]_]*\>"
|
||||||
syn match libertyxdrNumber "\<0\>\|\(-\|\<\)[1-9][[:digit:]]*\>"
|
syn match libertyxdrNumber "\<0\>\|\(-\|\<\)[1-9][[:digit:]]*\>"
|
||||||
syn keyword libertyxdrKeyword const enum struct union switch case
|
syn keyword libertyxdrKeyword const enum struct union switch case default
|
||||||
syn keyword libertyxdrType bool u8 u16 u32 u64 i8 i16 i32 i64 string void
|
syn keyword libertyxdrType bool u8 u16 u32 u64 i8 i16 i32 i64 string void
|
||||||
|
|
||||||
let b:current_syntax = "libertyxdr"
|
let b:current_syntax = "libertyxdr"
|
||||||
|
|||||||
@@ -25,5 +25,7 @@ struct Struct {
|
|||||||
union Onion switch (Enum tag) {
|
union Onion switch (Enum tag) {
|
||||||
case NOTHING:
|
case NOTHING:
|
||||||
void;
|
void;
|
||||||
|
default:
|
||||||
|
void;
|
||||||
} o;
|
} o;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# lxdrgen.awk: an XDR-derived code generator for network protocols.
|
# lxdrgen.awk: an XDR-derived code generator for network protocols.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2022 - 2023, Přemysl Eric Janouch <p@janouch.name>
|
# Copyright (c) 2022 - 2025, Přemysl Eric Janouch <p@janouch.name>
|
||||||
# SPDX-License-Identifier: 0BSD
|
# SPDX-License-Identifier: 0BSD
|
||||||
#
|
#
|
||||||
# Usage: env LC_ALL=C awk -f lxdrgen.awk -f lxdrgen-{c,go,mjs}.awk \
|
# Usage: env LC_ALL=C awk -f lxdrgen.awk -f lxdrgen-{c,go,mjs}.awk \
|
||||||
@@ -218,7 +218,7 @@ function defstruct( name, d, cg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function defunion( name, tag, tagtype, tagvalue, cg, scg, d, a, i,
|
function defunion( name, tag, tagtype, tagvalue, cg, scg, d, a, i,
|
||||||
unseen, exhaustive) {
|
unseen, defaulted, exhaustive) {
|
||||||
delete cg[0]
|
delete cg[0]
|
||||||
delete scg[0]
|
delete scg[0]
|
||||||
delete d[0]
|
delete d[0]
|
||||||
@@ -249,9 +249,22 @@ function defunion( name, tag, tagtype, tagvalue, cg, scg, d, a, i,
|
|||||||
if (!unseen[tagvalue]--)
|
if (!unseen[tagvalue]--)
|
||||||
fatal("no such value or duplicate case: " tagtype "." tagvalue)
|
fatal("no such value or duplicate case: " tagtype "." tagvalue)
|
||||||
codegen_struct_tag(tag, scg)
|
codegen_struct_tag(tag, scg)
|
||||||
|
} else if (accept("default")) {
|
||||||
|
if (tagvalue)
|
||||||
|
codegen_union_struct(name, tagvalue, cg, scg)
|
||||||
|
|
||||||
|
expect(accept(":"))
|
||||||
|
if (defaulted)
|
||||||
|
fatal("duplicate default")
|
||||||
|
|
||||||
|
tagvalue = ""
|
||||||
|
defaulted = 1
|
||||||
} else if (tagvalue) {
|
} else if (tagvalue) {
|
||||||
if (readfield(d))
|
if (readfield(d))
|
||||||
codegen_struct_field(d, scg)
|
codegen_struct_field(d, scg)
|
||||||
|
} else if (defaulted) {
|
||||||
|
if (readfield(d))
|
||||||
|
fatal("default must not contain fields")
|
||||||
} else {
|
} else {
|
||||||
fatal("union fields must fall under a case")
|
fatal("union fields must fall under a case")
|
||||||
}
|
}
|
||||||
@@ -259,11 +272,17 @@ function defunion( name, tag, tagtype, tagvalue, cg, scg, d, a, i,
|
|||||||
if (tagvalue)
|
if (tagvalue)
|
||||||
codegen_union_struct(name, tagvalue, cg, scg)
|
codegen_union_struct(name, tagvalue, cg, scg)
|
||||||
|
|
||||||
# Unseen cases are simply not recognized/allowed.
|
# Unseen cases are only recognized/allowed when default is present.
|
||||||
exhaustive = 1
|
exhaustive = 1
|
||||||
for (i in unseen)
|
for (i in unseen)
|
||||||
if (i && unseen[i])
|
if (i && unseen[i]) {
|
||||||
exhaustive = 0
|
if (defaulted) {
|
||||||
|
codegen_struct_tag(tag, scg)
|
||||||
|
codegen_union_struct(name, i, cg, scg)
|
||||||
|
} else {
|
||||||
|
exhaustive = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Types[name] = "union"
|
Types[name] = "union"
|
||||||
codegen_union(name, cg, exhaustive)
|
codegen_union(name, cg, exhaustive)
|
||||||
|
|||||||
@@ -890,10 +890,11 @@ environ_map_serialize (struct str_map *env, struct strv *envv)
|
|||||||
static int
|
static int
|
||||||
spawn_protected (lua_State *L)
|
spawn_protected (lua_State *L)
|
||||||
{
|
{
|
||||||
struct spawn_context *ctx = lua_touserdata (L, 1);
|
struct spawn_context *ctx = lua_touserdata (L, lua_upvalueindex (1));
|
||||||
|
luaL_checktype (L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
// Step 1: Prepare process environment.
|
// Step 1: Prepare process environment.
|
||||||
if (xlua_getfield (L, 2, "environ", LUA_TTABLE, true))
|
if (xlua_getfield (L, 1, "environ", LUA_TTABLE, true))
|
||||||
{
|
{
|
||||||
environ_map_update (&ctx->env, L);
|
environ_map_update (&ctx->env, L);
|
||||||
lua_pop (L, 1);
|
lua_pop (L, 1);
|
||||||
@@ -913,11 +914,11 @@ spawn_protected (lua_State *L)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Step 3: Prepare process command line.
|
// Step 3: Prepare process command line.
|
||||||
size_t argc = lua_rawlen (L, 2);
|
size_t argc = lua_rawlen (L, 1);
|
||||||
for (size_t i = 1; i <= argc; i++)
|
for (size_t i = 1; i <= argc; i++)
|
||||||
{
|
{
|
||||||
lua_pushinteger (L, i);
|
lua_pushinteger (L, i);
|
||||||
lua_rawget (L, 2);
|
lua_rawget (L, 1);
|
||||||
const char *arg = lua_tostring (L, -1);
|
const char *arg = lua_tostring (L, -1);
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return luaL_error (L, "spawn arguments must be strings");
|
return luaL_error (L, "spawn arguments must be strings");
|
||||||
@@ -1004,23 +1005,24 @@ spawn_protected (lua_State *L)
|
|||||||
static int
|
static int
|
||||||
xlua_spawn (lua_State *L)
|
xlua_spawn (lua_State *L)
|
||||||
{
|
{
|
||||||
luaL_checktype (L, 1, LUA_TTABLE);
|
|
||||||
|
|
||||||
lua_pushcfunction (L, xlua_error_handler);
|
lua_pushcfunction (L, xlua_error_handler);
|
||||||
lua_pushcfunction (L, spawn_protected);
|
lua_insert (L, 1);
|
||||||
|
|
||||||
|
struct spawn_context ctx = {};
|
||||||
|
lua_pushlightuserdata (L, &ctx);
|
||||||
|
lua_pushcclosure (L, spawn_protected, 1);
|
||||||
|
lua_insert (L, 2);
|
||||||
|
|
||||||
// There are way too many opportunities for Lua to throw,
|
// There are way too many opportunities for Lua to throw,
|
||||||
// so maintain a context to clean up in one go.
|
// so maintain a context to clean up in one go.
|
||||||
struct spawn_context ctx = spawn_context_make ();
|
ctx = spawn_context_make ();
|
||||||
lua_pushlightuserdata (L, &ctx);
|
int result = lua_pcall (L, lua_gettop (L) - 2, 1, 1);
|
||||||
lua_rotate (L, 1, -1);
|
|
||||||
int result = lua_pcall (L, 2, 1, -4);
|
|
||||||
spawn_context_free (&ctx);
|
spawn_context_free (&ctx);
|
||||||
if (result)
|
if (result)
|
||||||
return lua_error (L);
|
return lua_error (L);
|
||||||
|
|
||||||
// Remove the error handler ("good programming practice").
|
// Remove the error handler ("good programming practice").
|
||||||
lua_remove (L, -2);
|
lua_remove (L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user