refactor: object to string method

This commit is contained in:
DanyLE
2025-07-07 21:32:58 +02:00
parent b3d6ba9a54
commit bdd6bae1a9
3 changed files with 27 additions and 6 deletions

View File

@ -3,7 +3,6 @@
G_DEFINE_ABSTRACT_TYPE(DiyaObject, diya_object, G_TYPE_OBJECT) G_DEFINE_ABSTRACT_TYPE(DiyaObject, diya_object, G_TYPE_OBJECT)
static void diya_object_finalize(GObject* object) static void diya_object_finalize(GObject* object)
{ {
g_debug("diya_object_finalize: %s", diya_object_to_string(object)); g_debug("diya_object_finalize: %s", diya_object_to_string(object));

View File

@ -28,7 +28,7 @@ struct _DiyaForeignWindow
gchar* title; gchar* title;
enum diya_win_state state; enum diya_win_state state;
DiyaForeignWindow * parent_win; DiyaForeignWindow * parent_win;
gchar string[128]; gchar* string;
}; };
G_DEFINE_FINAL_TYPE(DiyaForeignWindow, diya_foreign_window, DIYA_TYPE_SHELL_OBJECT) G_DEFINE_FINAL_TYPE(DiyaForeignWindow, diya_foreign_window, DIYA_TYPE_SHELL_OBJECT)
@ -46,6 +46,11 @@ static void diya_foreign_window_finalize(GObject* object)
g_free(self->title); g_free(self->title);
self->title = NULL; self->title = NULL;
} }
if(self->string)
{
g_free(self->string);
self->string = NULL;
}
G_OBJECT_CLASS(diya_foreign_window_parent_class)->finalize(object); G_OBJECT_CLASS(diya_foreign_window_parent_class)->finalize(object);
} }
@ -125,13 +130,18 @@ static void diya_foreign_window_init(DiyaForeignWindow *self)
//self->shell = NULL; //self->shell = NULL;
self->state = DIYA_WIN_STATE_NONE; self->state = DIYA_WIN_STATE_NONE;
self->title = NULL; self->title = NULL;
memset(self->string, 0, sizeof(self->string)); self->string = NULL;
} }
static const gchar* diya_foreign_window_to_string(DiyaObject* object) static const gchar* diya_foreign_window_to_string(DiyaObject* object)
{ {
DiyaForeignWindow* self = DIYA_FOREIGN_WINDOW(object); DiyaForeignWindow* self = DIYA_FOREIGN_WINDOW(object);
g_snprintf(self->string, sizeof(self->string), "Window 0x%" PRIXPTR ": %s (%s)", (uintptr_t) self->handle, self->appid?self->appid:"", self->title?self->title:""); if(!self->string)
{
self->string = (char*) malloc(128);
g_snprintf(self->string, 128, "Window 0x%" PRIXPTR ": %s (%s)", (uintptr_t) self->handle, self->appid?self->appid:"", self->title?self->title:"");
}
return self->string; return self->string;
} }

View File

@ -9,6 +9,7 @@ struct _DiyaIdleNotification
DiyaShellObject parent; DiyaShellObject parent;
struct ext_idle_notification_v1* notification; struct ext_idle_notification_v1* notification;
guint timeout; guint timeout;
gchar* str;
}; };
G_DEFINE_FINAL_TYPE(DiyaIdleNotification, diya_idle_notification, DIYA_TYPE_SHELL_OBJECT) G_DEFINE_FINAL_TYPE(DiyaIdleNotification, diya_idle_notification, DIYA_TYPE_SHELL_OBJECT)
@ -23,6 +24,11 @@ static void diya_idle_notification_finalize(GObject* object)
self->notification = NULL; self->notification = NULL;
} }
g_debug("diya_idle_notification_finalize: %s", diya_object_to_string(object)); g_debug("diya_idle_notification_finalize: %s", diya_object_to_string(object));
if(self->str)
{
g_free(self->str);
self->str = NULL;
}
G_OBJECT_CLASS(diya_idle_notification_parent_class)->finalize(object); G_OBJECT_CLASS(diya_idle_notification_parent_class)->finalize(object);
} }
@ -37,12 +43,18 @@ static void diya_idle_notification_dispose(GObject* object)
static void diya_idle_notification_init(DiyaIdleNotification * self) static void diya_idle_notification_init(DiyaIdleNotification * self)
{ {
self->notification = NULL; self->notification = NULL;
self->str = NULL;
} }
static const gchar* diya_idle_notification_to_string(DiyaObject* object) static const gchar* diya_idle_notification_to_string(DiyaObject* object)
{ {
(void) object; DiyaIdleNotification * self = DIYA_IDLE_NOTIFICATION(object);
return "DiyaIdleNotification - wayland client handle object"; if(!self->str)
{
self->str = (gchar*) malloc(64);
g_snprintf(self->str, 64, "DiyaIdleNotification for timeout: %d (ms)", self->timeout);
}
return self->str;
} }
static void diya_idle_notification_class_init(DiyaIdleNotificationClass *class) static void diya_idle_notification_class_init(DiyaIdleNotificationClass *class)