add wm state logging
This commit is contained in:
@ -103,6 +103,11 @@ void wm_maprequest_handler(Wm *wm, XMapRequestEvent e)
|
|||||||
|
|
||||||
wm_layout(wm, c->m);
|
wm_layout(wm, c->m);
|
||||||
wm_client_focus(wm, c);
|
wm_client_focus(wm, c);
|
||||||
|
|
||||||
|
if (wm->log_after_maprequest) {
|
||||||
|
wm_log_state(wm, "after wm_kb_spawn", WM_LOGFILENAME);
|
||||||
|
wm->log_after_maprequest = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_motion_handler(Wm *wm, XMotionEvent e)
|
void wm_motion_handler(Wm *wm, XMotionEvent e)
|
||||||
|
40
src/util.c
40
src/util.c
@ -1,5 +1,6 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "wm.h"
|
#include "wm.h"
|
||||||
|
#include <time.h>
|
||||||
#include <json-c/json_object.h>
|
#include <json-c/json_object.h>
|
||||||
#include <json-c/json_tokener.h>
|
#include <json-c/json_tokener.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -150,13 +151,50 @@ char* wm_treenode_to_str(TreeNode *node)
|
|||||||
json_object_object_add(jobj, "client", json_object_new_uint64((uint64_t)node->client));
|
json_object_object_add(jobj, "client", json_object_new_uint64((uint64_t)node->client));
|
||||||
json_object_object_add(jobj, "id", json_object_new_uint64((uint64_t)node->id));
|
json_object_object_add(jobj, "id", json_object_new_uint64((uint64_t)node->id));
|
||||||
|
|
||||||
|
char *ret = strdup(json_object_to_json_string_ext(jobj, JSON_C_TO_STRING_PRETTY));
|
||||||
|
|
||||||
char *ret = strdup(json_object_to_json_string(jobj));
|
|
||||||
json_object_put(jobj);
|
json_object_put(jobj);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PtrArray wm_nonempty_workspaces_to_strptrarray(Wm *wm)
|
||||||
|
{
|
||||||
|
PtrArray ret = wm_ptrarray_new();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < wm->smon->wscount; i++) {
|
||||||
|
TreeNode *node = wm->smon->workspaces[i].tree;
|
||||||
|
if (!wm_treenode_is_empty(node) || (node->type == NODE_CLIENT && node->client))
|
||||||
|
wm_ptrarray_push(&ret, wm_treenode_to_str(wm->smon->workspaces[i].tree));
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_PRINT("%s returning %d\n", __func__, ret.size);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wm_log_state(Wm *wm, const char *prefixstr, const char* logfile)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULL(prefixstr);
|
||||||
|
RETURN_IF_NULL(logfile);
|
||||||
|
|
||||||
|
PtrArray ws_str = wm_nonempty_workspaces_to_strptrarray(wm);
|
||||||
|
FILE* fptr = fopen(logfile, "a");
|
||||||
|
if (!fptr) {
|
||||||
|
fprintf(stderr, "wm: could not open log file %s\n", logfile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefixstr) fprintf(fptr, "%lu %s\n", time(NULL), prefixstr);
|
||||||
|
for (size_t i = 0; i < ws_str.size; i++) {
|
||||||
|
fprintf(fptr, "%s\n", (char*)ws_str.ptrs[i]);
|
||||||
|
free(ws_str.ptrs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fptr);
|
||||||
|
wm_ptrarray_free(&ws_str);
|
||||||
|
}
|
||||||
|
|
||||||
void wm_treenode_print(TreeNode *node)
|
void wm_treenode_print(TreeNode *node)
|
||||||
{
|
{
|
||||||
char *str = wm_treenode_to_str(node);
|
char *str = wm_treenode_to_str(node);
|
||||||
|
@ -96,6 +96,7 @@ TreeNode* wm_treenode_ptr_find_client_node(TreeNode *root, Client *client);
|
|||||||
PtrArray wm_treenode_find_client_nodes_ptr(TreeNode *root);
|
PtrArray wm_treenode_find_client_nodes_ptr(TreeNode *root);
|
||||||
TreeNode* wm_treenode_split_get_sibling(TreeNode *node);
|
TreeNode* wm_treenode_split_get_sibling(TreeNode *node);
|
||||||
PtrArray wm_all_nodes_to_ptrarray(TreeNode *root);
|
PtrArray wm_all_nodes_to_ptrarray(TreeNode *root);
|
||||||
|
void wm_log_state(Wm *wm, const char *prefixstr, const char* logfile);
|
||||||
|
|
||||||
ClientArray wm_clientarray_new();
|
ClientArray wm_clientarray_new();
|
||||||
void wm_clientarray_push(ClientArray *arr, Client node);
|
void wm_clientarray_push(ClientArray *arr, Client node);
|
||||||
|
28
src/wm.c
28
src/wm.c
@ -543,6 +543,8 @@ void wm_kb_spawn(Wm *wm, Arg *args)
|
|||||||
DEBUG_PRINT("args sl 0: %s\n", args->sl[0])
|
DEBUG_PRINT("args sl 0: %s\n", args->sl[0])
|
||||||
DEBUG_PRINT("args count: %d\n", args->count)
|
DEBUG_PRINT("args count: %d\n", args->count)
|
||||||
|
|
||||||
|
WM_LOG_STATE_START(wm);
|
||||||
|
|
||||||
if (args->sl[args->count-1] != NULL) {
|
if (args->sl[args->count-1] != NULL) {
|
||||||
fprintf(stderr, "%s recieved non null-terminated args. Returning\n",
|
fprintf(stderr, "%s recieved non null-terminated args. Returning\n",
|
||||||
__func__);
|
__func__);
|
||||||
@ -556,6 +558,8 @@ void wm_kb_spawn(Wm *wm, Arg *args)
|
|||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wm->log_after_maprequest = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_kb_exit(Wm* wm, Arg *args)
|
void wm_kb_exit(Wm* wm, Arg *args)
|
||||||
@ -565,26 +569,38 @@ void wm_kb_exit(Wm* wm, Arg *args)
|
|||||||
|
|
||||||
void wm_kb_kill(Wm *wm, Arg *args)
|
void wm_kb_kill(Wm *wm, Arg *args)
|
||||||
{
|
{
|
||||||
|
WM_LOG_STATE_START(wm);
|
||||||
|
|
||||||
Client *c;
|
Client *c;
|
||||||
|
|
||||||
c = wm_client_get_focused(wm);
|
c = wm_client_get_focused(wm);
|
||||||
RETURN_IF_NULL(c)
|
RETURN_IF_NULL(c)
|
||||||
|
|
||||||
wm_client_kill(wm, c);
|
wm_client_kill(wm, c);
|
||||||
|
|
||||||
|
WM_LOG_STATE_END(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_kb_switch_ws(Wm *wm, Arg *args)
|
void wm_kb_switch_ws(Wm *wm, Arg *args)
|
||||||
{
|
{
|
||||||
RETURN_IF_NULL(args)
|
RETURN_IF_NULL(args)
|
||||||
|
|
||||||
|
WM_LOG_STATE_START(wm);
|
||||||
|
|
||||||
wm_switch_ws(wm, args->i);
|
wm_switch_ws(wm, args->i);
|
||||||
|
|
||||||
|
WM_LOG_STATE_END(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_kb_move_client_ws(Wm *wm, Arg *args)
|
void wm_kb_move_client_ws(Wm *wm, Arg *args)
|
||||||
{
|
{
|
||||||
RETURN_IF_NULL(args)
|
RETURN_IF_NULL(args)
|
||||||
|
|
||||||
|
WM_LOG_STATE_START(wm);
|
||||||
|
|
||||||
wm_move_client_ws(wm, args->i);
|
wm_move_client_ws(wm, args->i);
|
||||||
|
|
||||||
|
WM_LOG_STATE_END(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_kb_focus_dir(Wm *wm, Arg *args)
|
void wm_kb_focus_dir(Wm *wm, Arg *args)
|
||||||
@ -592,9 +608,13 @@ void wm_kb_focus_dir(Wm *wm, Arg *args)
|
|||||||
Client *c;
|
Client *c;
|
||||||
RETURN_IF_NULL(args)
|
RETURN_IF_NULL(args)
|
||||||
|
|
||||||
|
WM_LOG_STATE_START(wm);
|
||||||
|
|
||||||
c = wm_client_get_focused(wm);
|
c = wm_client_get_focused(wm);
|
||||||
|
|
||||||
wm_client_focus_dir(wm, c, args->i);
|
wm_client_focus_dir(wm, c, args->i);
|
||||||
|
|
||||||
|
WM_LOG_STATE_END(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_kb_move_dir(Wm *wm, Arg *args)
|
void wm_kb_move_dir(Wm *wm, Arg *args)
|
||||||
@ -602,16 +622,24 @@ void wm_kb_move_dir(Wm *wm, Arg *args)
|
|||||||
Client *c;
|
Client *c;
|
||||||
RETURN_IF_NULL(args)
|
RETURN_IF_NULL(args)
|
||||||
|
|
||||||
|
WM_LOG_STATE_START(wm);
|
||||||
|
|
||||||
c = wm_client_get_focused(wm);
|
c = wm_client_get_focused(wm);
|
||||||
|
|
||||||
wm_client_swap_dir(wm, c, args->i);
|
wm_client_swap_dir(wm, c, args->i);
|
||||||
|
|
||||||
|
WM_LOG_STATE_END(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_kb_switch_split_mode(Wm *wm, Arg *args)
|
void wm_kb_switch_split_mode(Wm *wm, Arg *args)
|
||||||
{
|
{
|
||||||
RETURN_IF_NULL(args)
|
RETURN_IF_NULL(args)
|
||||||
|
|
||||||
|
WM_LOG_STATE_START(wm);
|
||||||
|
|
||||||
wm->smon->workspaces[wm->smon->selws].split = args->i;
|
wm->smon->workspaces[wm->smon->selws].split = args->i;
|
||||||
|
|
||||||
|
WM_LOG_STATE_END(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr wm_socket_init(Wm *wm)
|
struct sockaddr wm_socket_init(Wm *wm)
|
||||||
|
13
src/wm.h
13
src/wm.h
@ -65,6 +65,18 @@ if (c == NULL) \
|
|||||||
|
|
||||||
#define CURRENT_WS(wm) (wm)->smon->workspaces[(wm)->smon->selws]
|
#define CURRENT_WS(wm) (wm)->smon->workspaces[(wm)->smon->selws]
|
||||||
|
|
||||||
|
#define WM_LOGFILENAME "./log"
|
||||||
|
|
||||||
|
#define WM_LOG_STATE_START(wm) do { \
|
||||||
|
wm_log_state(wm, __func__, WM_LOGFILENAME); \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#define WM_LOG_STATE_END(wm) do { \
|
||||||
|
char __prefix[4096] = {0}; \
|
||||||
|
snprintf(__prefix, 4096, "after %s", __func__); \
|
||||||
|
wm_log_state(wm, __prefix, WM_LOGFILENAME); \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
typedef struct Client Client;
|
typedef struct Client Client;
|
||||||
typedef struct Workspace Workspace;
|
typedef struct Workspace Workspace;
|
||||||
typedef struct Monitor Monitor;
|
typedef struct Monitor Monitor;
|
||||||
@ -124,6 +136,7 @@ struct Wm {
|
|||||||
// bool cfg_focus_on_motion;
|
// bool cfg_focus_on_motion;
|
||||||
Config config;
|
Config config;
|
||||||
|
|
||||||
|
bool log_after_maprequest;
|
||||||
int socket_fd;
|
int socket_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user