Skip to content

Commit

Permalink
scanner: merge multiple declarations of MpdClient and SwayClient
Browse files Browse the repository at this point in the history
  • Loading branch information
LBCrion committed Sep 12, 2024
1 parent 94a577a commit 64246a8
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gchar *config_get_value ( GScanner *, gchar *, gboolean, gchar **);
void config_menu_items ( GScanner *scanner, GtkWidget *menu );
gboolean config_flowgrid_property ( GScanner *scanner, GtkWidget *widget );
void config_scanner ( GScanner *scanner );
gboolean config_scanner_source ( GScanner *scanner );
void config_layout ( GScanner *, GtkWidget * );
gboolean config_widget_child ( GScanner *scanner, GtkWidget *container );
gboolean config_include ( GScanner *scanner, GtkWidget *container );
Expand Down
2 changes: 1 addition & 1 deletion src/config/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static ScanFile *config_source ( GScanner *scanner, gint source )
return NULL;
}

file = scanner_file_new ( source, fname, trigger, flags );
file = scanner_file_new(source, fname, trigger, flags);
while(!config_is_section_end(scanner))
config_var(scanner, file);

Expand Down
17 changes: 12 additions & 5 deletions src/mpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ typedef struct _MpdState {
GQueue *commands;
} MpdState;

ScanFile *mpd_file;

#define MPD_STATE(x) ((MpdState *)(x))

gboolean client_mpd_connect ( Client *client )
Expand Down Expand Up @@ -75,14 +77,20 @@ GIOStatus client_mpd_respond ( Client *client )
return s;
}


void client_mpd ( ScanFile *file )
{
Client *client;

if( !file || !file->fname )
return;

if(mpd_file)
{
scanner_file_attach(mpd_file->trigger, mpd_file);
scanner_file_merge(mpd_file, file);
return;
}

client = g_malloc0(sizeof(Client));
client->file = file;
client->data = g_malloc0(sizeof(MpdState));
Expand All @@ -94,23 +102,22 @@ void client_mpd ( ScanFile *file )
file->trigger = g_intern_static_string("mpd");
file->source = SO_CLIENT;
file->client = client;
mpd_file = file;

client_attach(client);
}

void client_mpd_command ( gchar *command )
{
ScanFile *file;
Client *client;

if(!command)
return;

file = scanner_file_get("mpd");
if(!file)
if(!mpd_file)
return;

client = file->client;
client = mpd_file->client;
if(!client || !client->out || !client->data)
return;

Expand Down
14 changes: 14 additions & 0 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ ScanFile *scanner_file_get ( gchar *trigger )
return g_hash_table_lookup(trigger_list, (void *)g_intern_string(trigger));
}

void scanner_file_merge ( ScanFile *keep, ScanFile *temp )
{
GList *iter;

file_list = g_list_remove(file_list, temp);

for(iter=temp->vars; iter; iter=g_list_next(iter))
((ScanVar *)(iter->data))->file = keep;
keep->vars = g_list_concat(keep->vars, temp->vars);

g_free(temp->fname);
g_free(temp);
}

ScanFile *scanner_file_new ( gint source, gchar *fname,
gchar *trigger, gint flags )
{
Expand Down
1 change: 1 addition & 0 deletions src/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ GIOStatus scanner_file_update ( GIOChannel *, ScanFile *, gsize * );
int scanner_glob_file ( ScanFile * );
void *scanner_get_value ( gchar *ident, gboolean update, ExprCache *expr );
void scanner_var_new ( gchar *, ScanFile *, gchar *, guint, gint );
void scanner_file_merge ( ScanFile *keep, ScanFile *temp );
gchar *scanner_parse_identifier ( gchar *id, gchar **fname );
ScanFile *scanner_file_get ( gchar *trigger );
ScanFile *scanner_file_new ( gint , gchar *, gchar *, gint );
Expand Down
2 changes: 1 addition & 1 deletion src/snimenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static void sni_menu_layout_updated_cb (GDBusConnection *con,
gint32 id;

g_variant_get(parameters, "(ui)", &rev, &id);
g_message("sni menu: update: %s, id: %d, rev: %u", sni->dest, id, rev);
g_debug("sni menu: update: %s, id: %d, rev: %u", sni->dest, id, rev);
g_dbus_connection_call(sni_get_connection(), sni->dest, sni->menu_path,
sni_menu_iface, "GetLayout", g_variant_new("(iias)", 0, -1, NULL),
G_VARIANT_TYPE("(u(ia{sv}av))"), G_DBUS_CALL_FLAGS_NONE, -1, NULL,
Expand Down
8 changes: 7 additions & 1 deletion src/sway_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ static void sway_traverse_tree ( struct json_object *obj, const gchar *parent,

void sway_ipc_client_init ( ScanFile *file )
{
sway_file = file;
if(sway_file)
{
scanner_file_attach(sway_file->trigger, sway_file);
scanner_file_merge(sway_file, file);
}
else
sway_file = file;
}

static workspace_t *sway_ipc_workspace_new ( struct json_object *obj )
Expand Down

0 comments on commit 64246a8

Please sign in to comment.