Skip to content

Commit

Permalink
New window template
Browse files Browse the repository at this point in the history
  • Loading branch information
jszczerbinsky committed Feb 17, 2024
1 parent 3fc4a7a commit fd39c40
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 88 deletions.
38 changes: 35 additions & 3 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,50 @@ static void reloadMonitorListBox()

g_list_free(rows);

char iconPath[PATH_MAX];
getAppDir(iconPath, APP_DIR_SHARE);
#ifdef __WIN32
const char *format = "%s\\%s\\%s\\%s";
#else
const char *format = "%s/%s/%s/%s";
#endif
sprintf(
iconPath, format, iconPath, "window_templates", "assets", "screen-monitor-svgrepo-com.svg"
);

int monitorsCount;
MonitorInfo *monitors;

monitors = scanMonitors(&monitorsCount);

for (int i = 0; i < monitorsCount; i++)
{
GtkWidget *label = gtk_label_new(monitors[i].name);
GtkWidget *row = gtk_list_box_row_new();
gtk_container_add(GTK_CONTAINER(row), label);
char resStr[12];
sprintf(resStr, "%dx%d", monitors[i].bounds.w, monitors[i].bounds.h);

GtkWidget *nameLabel = gtk_label_new(monitors[i].name);
GtkWidget *resLabel = gtk_label_new(resStr);
GtkWidget *icon = gtk_image_new_from_file(iconPath);

GtkWidget *labelBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(labelBox), nameLabel);
gtk_container_add(GTK_CONTAINER(labelBox), resLabel);
gtk_box_set_child_packing(GTK_BOX(labelBox), nameLabel, 1, 1, 0, GTK_PACK_START);

GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add(GTK_CONTAINER(box), icon);
gtk_container_add(GTK_CONTAINER(box), labelBox);
gtk_box_set_child_packing(GTK_BOX(box), labelBox, 1, 1, 0, GTK_PACK_START);

GtkWidget *row = gtk_list_box_row_new();
gtk_container_add(GTK_CONTAINER(row), box);

gtk_list_box_insert(GTK_LIST_BOX(monitorListBox), row, 0);

char *nameBuff = malloc(sizeof(strlen(monitors[i].name)));
strcpy(nameBuff, monitors[i].name);
g_object_set_data(G_OBJECT(row), "monitor_name", (gpointer)nameBuff);

gtk_widget_show_all(row);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/windowHandlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ G_MODULE_EXPORT void MonitorWindowShow()

// Find selected monitor name
GtkListBoxRow *listBoxRow = gtk_list_box_get_selected_row(GTK_LIST_BOX(monitorListBox));
GList *children = gtk_container_get_children(GTK_CONTAINER(listBoxRow));
const char *monitorName = gtk_label_get_label(GTK_LABEL(children->data));
const char *monitorName = g_object_get_data(G_OBJECT(listBoxRow), "monitor_name");
gtk_label_set_text(GTK_LABEL(monitorNameLabel), monitorName);
g_list_free(children);

// Read configuration from config file
MonitorConfig mc;
Expand Down
7 changes: 7 additions & 0 deletions src/window_templates/assets/cross-close-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/window_templates/assets/github-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/window_templates/assets/image-photo-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/window_templates/assets/question-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/window_templates/assets/screen-monitor-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/window_templates/assets/settings-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fd39c40

Please sign in to comment.