Skip to content

Commit

Permalink
cleanup ipc in prep for pager
Browse files Browse the repository at this point in the history
  • Loading branch information
LBCrion committed Dec 28, 2020
1 parent ad0a342 commit 7fa3036
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
18 changes: 14 additions & 4 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,33 @@

const gint8 magic[6] = {0x69, 0x33, 0x2d, 0x69, 0x70, 0x63};

json_object *ipc_poll ( int sock )
json_object *ipc_poll ( int sock, gint32 *etype )
{
gint8 ipc_header[14];
gchar *response = NULL;
gint32 plen;
size_t pos=0;
ssize_t rlen;

if(recv(sock,(gchar *)ipc_header,sizeof(ipc_header),0)==sizeof(ipc_header))
while(pos<sizeof(ipc_header))
{
memcpy(&plen,ipc_header+sizeof(magic)+sizeof(plen),sizeof(plen));
rlen = recv(sock,(gchar *)ipc_header,sizeof(ipc_header)-pos,0);
if (rlen<=0)
break;
pos+=rlen;
}

if(pos==sizeof(ipc_header))
{
pos=0;
memcpy(etype,ipc_header+sizeof(magic)+sizeof(plen),sizeof(plen));
memcpy(&plen,ipc_header+sizeof(magic),sizeof(plen));
response = g_malloc(plen+1);
if ( response != NULL)
{
while(pos<plen)
{
ssize_t rlen = recv(sock,(gchar *)response,plen,0);
rlen = recv(sock,(gchar *)response,plen-pos,0);
if (rlen<=0)
break;
pos+=rlen;
Expand Down
3 changes: 2 additions & 1 deletion src/placement.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ json_object *placement_find_pid ( json_object *obj, gint64 pid )
void place_window ( gint64 pid, struct context *context )
{
int sock;
gint32 etype;
char buff[256];
struct rect r;
json_object *obj, *node;
sock = ipc_open();
ipc_send(sock,4,"");
obj = ipc_poll(sock);
obj = ipc_poll(sock,&etype);
node = placement_find_pid ( obj, pid );
placement_location(context,node,pid,&r);
json_object_put(obj);
Expand Down
8 changes: 5 additions & 3 deletions src/sfwbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ gint shell_timer ( struct context *context )
{
json_object *obj;
struct ipc_event ev;
gint32 etype;

scanner_expire(context->scan_list);
widget_update_all(context);
obj = ipc_poll(context->ipc);
obj = ipc_poll(context->ipc,&etype);
while (obj != NULL)
{
ev = ipc_parse_event(obj);
dispatch_event(&ev,context);
if(etype==0x80000003)
dispatch_event(&ev,context);
json_object_put(obj);
obj = ipc_poll(context->ipc);
obj = ipc_poll(context->ipc,&etype);
}
return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sfwbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct scan_file {

int ipc_open();
int ipc_subscribe( int sock );
json_object *ipc_poll( int sock );
json_object *ipc_poll( int sock, gint32 *etype );
int ipc_send ( int sock, gint32 type, gchar *command );
struct ipc_event ipc_parse_event ( json_object *obj );

Expand Down
3 changes: 2 additions & 1 deletion src/taskbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ void taskbar_populate ( struct context *context )
{
json_object *obj;
int sock;
gint32 etype;
sock=ipc_open();
if(sock==-1)
return;
ipc_send(sock,4,"");
obj = ipc_poll(sock);
obj = ipc_poll(sock,&etype);
if(obj!=NULL)
{
taskbar_traverse_tree(obj,context);
Expand Down

0 comments on commit 7fa3036

Please sign in to comment.