// File: eiskalteschatten[P]developersnotebook/src/windows/MainWindow.cpp
// Function: MainWindow::activate(_GtkApplication*, MainWindow*)
void MainWindow::activate(GtkApplication *app, MainWindow *mw) {
    PreferencesModel *preferences_model = new PreferencesModel();
    int window_width                    = preferences_model->get_window_width();
    int window_height                   = preferences_model->get_window_height();
    bool window_maximized               = preferences_model->get_window_maximized();

    mw->window = gtk_application_window_new(app);
    gtk_window_set_title(GTK_WINDOW(mw->window), Constants::application_name.c_str());
    gtk_window_set_position(GTK_WINDOW(mw->window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(mw->window), window_width, window_height);

    #ifndef __APPLE__
        Image logo("icon", "svg", mw->get_path_to_exec(), 32, 32);
        std::string path = logo.get_path();
        gtk_window_set_icon_from_file(GTK_WINDOW(mw->window), path.c_str(), NULL);
    #endif

    if (window_maximized) {
        gtk_window_maximize(GTK_WINDOW(mw->window));
    }

    mw->setup_css();
    mw->setup_grid();
    mw->setup_stack();

    MenuBar *menubar_obj = new MenuBar(mw);
    GtkWidget *menubar   = menubar_obj->get_menu_bar();
    gtk_grid_attach(GTK_GRID(mw->grid), menubar, 0, 0, 2, 1);

    gtk_widget_show_all(mw->window);

    menubar_obj->setup_macos_menu_bar();

    g_signal_connect(mw->window, "delete_event", G_CALLBACK(mw->save_and_close_window), NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x68, %edi
callq 0xa280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x180(%rbp)
callq 0x51710
jmp 0x1f421
movq -0x180(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x200f0
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20110
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20130
movb %al, -0x2d(%rbp)
movq -0x8(%rbp), %rdi
callq 0xaad0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x1a8(%rbp)
callq 0xb270
movq -0x1a8(%rbp), %rdi
movq %rax, %rsi
callq 0xa190
movq %rax, -0x1a0(%rbp)
leaq 0x57603(%rip), %rdi     # 0x76a98
callq 0xa1d0
movq -0x1a0(%rbp), %rdi
movq %rax, %rsi
callq 0xa3c0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x198(%rbp)
callq 0xb270
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0xa190
movq %rax, %rdi
movl $0x1, %esi
callq 0xa9d0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x190(%rbp)
callq 0xb270
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0xa190
movq %rax, %rdi
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0xb0a0
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0xaf80
movq -0x188(%rbp), %rdx
leaq 0x34340(%rip), %rsi     # 0x5386b
leaq -0xf8(%rbp), %rdi
callq 0x10f00
jmp 0x1f539
leaq -0x121(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0xaf80
movq -0x1b0(%rbp), %rdx
leaq 0x33b0f(%rip), %rsi     # 0x53069
leaq -0x120(%rbp), %rdi
callq 0x10f00
jmp 0x1f568
movq -0x10(%rbp), %rdi
callq 0x1f2a0
movq %rax, -0x1b8(%rbp)
jmp 0x1f57a
movq -0x1b8(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0xa230
jmp 0x1f58f
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
leaq -0x120(%rbp), %rdx
leaq -0x148(%rbp), %rcx
movl $0x20, %r9d
movl %r9d, %r8d
callq 0x138c0
jmp 0x1f5bb
leaq -0x148(%rbp), %rdi
callq 0xb430
leaq -0x120(%rbp), %rdi
callq 0xb430
leaq -0x121(%rbp), %rdi
callq 0xb410
leaq -0xf8(%rbp), %rdi
callq 0xb430
leaq -0xf9(%rbp), %rdi
callq 0xb410
leaq -0x168(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x20150
jmp 0x1f60c
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x1c8(%rbp)
callq 0xb270
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0xa190
movq %rax, -0x1c0(%rbp)
jmp 0x1f638
leaq -0x168(%rbp), %rdi
callq 0xa1d0
movq -0x1c0(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xac50
jmp 0x1f659
testb $0x1, -0x2d(%rbp)
je 0x1f75d
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x1d8(%rbp)
callq 0xb270
movq -0x1d8(%rbp), %rdi
movq %rax, %rsi
callq 0xa190
movq %rax, -0x1d0(%rbp)
jmp 0x1f68f
movq -0x1d0(%rbp), %rdi
callq 0xa3d0
jmp 0x1f69d
jmp 0x1f75d
movq -0x180(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x68, %esi
callq 0xa200
jmp 0x1f8be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1f72a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1f712
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1f706
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xb430
leaq -0x120(%rbp), %rdi
callq 0xb430
leaq -0x121(%rbp), %rdi
callq 0xb410
leaq -0xf8(%rbp), %rdi
callq 0xb430
leaq -0xf9(%rbp), %rdi
callq 0xb410
jmp 0x1f8be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1f8b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1f8a6
movq -0x10(%rbp), %rdi
callq 0x1f8d0
jmp 0x1f768
movq -0x10(%rbp), %rdi
callq 0x1fb00
jmp 0x1f773
movq -0x10(%rbp), %rdi
callq 0x1fc20
jmp 0x1f77e
movl $0x50, %edi
callq 0xa280
movq %rax, -0x1e0(%rbp)
jmp 0x1f791
movq -0x1e0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x20c70
jmp 0x1f7a3
movq -0x1e0(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rdi
callq 0x20180
movq %rax, -0x1e8(%rbp)
jmp 0x1f7c6
movq -0x1e8(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x1f8(%rbp)
callq 0xac20
movq -0x1f8(%rbp), %rdi
movq %rax, %rsi
callq 0xa190
movq %rax, -0x1f0(%rbp)
jmp 0x1f800
movq -0x1f0(%rbp), %rdi
movq -0x178(%rbp), %rsi
xorl %ecx, %ecx
movl $0x2, %r8d
movl $0x1, %r9d
movl %ecx, %edx
callq 0xad40
jmp 0x1f825
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0xaf30
jmp 0x1f834
movq -0x170(%rbp), %rdi
callq 0x213e0
jmp 0x1f842
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x34029(%rip), %rsi     # 0x5387a
leaq 0x6a8(%rip), %rdx       # 0x1ff00
xorl %r9d, %r9d
movl %r9d, %r8d
movq %r8, %rcx
callq 0xa380
jmp 0x1f868
leaq -0x168(%rbp), %rdi
callq 0xb430
leaq -0xd8(%rbp), %rdi
callq 0x13a50
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0x1e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x50, %esi
callq 0xa200
leaq -0x168(%rbp), %rdi
callq 0xb430
leaq -0xd8(%rbp), %rdi
callq 0x13a50
movq -0x20(%rbp), %rdi
callq 0xaa00
nopw (%rax,%rax)