ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/prefs_editor_gtk.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/prefs_editor_gtk.cpp (file contents):
Revision 1.32 by gbeauche, 2006-04-16T16:32:45Z vs.
Revision 1.38 by gbeauche, 2006-04-30T21:16:48Z

# Line 39 | Line 39
39   #include "prefs.h"
40   #include "prefs_editor.h"
41  
42 + #define DEBUG 0
43 + #include "debug.h"
44 +
45  
46   // Global variables
47   static GtkWidget *win;                          // Preferences window
48 < static bool start_clicked = true;       // Return value of PrefsEditor() function
48 > static bool start_clicked = false;      // Return value of PrefsEditor() function
49  
50  
51   // Prototypes
# Line 121 | Line 124 | static GtkWidget *make_pane(GtkWidget *n
124          GtkWidget *frame, *label, *box;
125  
126          frame = gtk_frame_new(NULL);
127 <        gtk_widget_show(frame);
125 <        gtk_container_border_width(GTK_CONTAINER(frame), 4);
126 <
127 <        label = gtk_label_new(GetString(title_id));
128 <        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
127 >        gtk_container_set_border_width(GTK_CONTAINER(frame), 4);
128  
129          box = gtk_vbox_new(FALSE, 4);
131        gtk_widget_show(box);
130          gtk_container_set_border_width(GTK_CONTAINER(box), 4);
131          gtk_container_add(GTK_CONTAINER(frame), box);
132 +
133 +        gtk_widget_show_all(frame);
134 +
135 +        label = gtk_label_new(GetString(title_id));
136 +        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
137          return box;
138   }
139  
# Line 516 | Line 519 | bool PrefsEditor(void)
519          gtk_box_pack_start(GTK_BOX(box), menu_bar, FALSE, TRUE, 0);
520  
521          GtkWidget *notebook = gtk_notebook_new();
519        gtk_widget_show(notebook);
522          gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
523          gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), FALSE);
524          gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0);
525 +        gtk_widget_realize(notebook);
526  
527          create_volumes_pane(notebook);
528          create_scsi_pane(notebook);
# Line 528 | Line 531 | bool PrefsEditor(void)
531          create_serial_pane(notebook);
532          create_memory_pane(notebook);
533          create_jit_pane(notebook);
534 +        gtk_widget_show(notebook);
535  
536          static const opt_desc buttons[] = {
537                  {STR_START_BUTTON, GTK_SIGNAL_FUNC(cb_start)},
# Line 708 | Line 712 | static GtkWidget *w_jit_cache_size;
712   static GtkWidget *w_jit_lazy_flush;
713   static GtkWidget *w_jit_follow_const_jumps;
714  
715 + // Are we running a JIT capable CPU?
716 + static bool is_jit_capable(void)
717 + {
718 + #if USE_JIT && (defined __i386__ || defined __x86_64__)
719 +        return true;
720 + #elif defined __APPLE__ && defined __MACH__
721 +        // XXX run-time detect so that we can use a PPC GUI prefs editor
722 +        static char cpu[10];
723 +        if (cpu[0] == 0) {
724 +                FILE *fp = popen("uname -p", "r");
725 +                if (fp == NULL)
726 +                        return false;
727 +                fgets(cpu, sizeof(cpu) - 1, fp);
728 +                fclose(fp);
729 +        }
730 +        if (cpu[0] == 'i' && cpu[2] == '8' && cpu[3] == '6') // XXX assuming i?86
731 +                return true;
732 + #endif
733 +        return false;
734 + }
735 +
736   // Set sensitivity of widgets
737   static void set_jit_sensitive(void)
738   {
# Line 746 | Line 771 | static void tb_jit_follow_const_jumps(Gt
771   // Read settings from widgets and set preferences
772   static void read_jit_settings(void)
773   {
774 < #if USE_JIT
750 <        bool jit_enabled = PrefsFindBool("jit");
774 >        bool jit_enabled = is_jit_capable() && PrefsFindBool("jit");
775          if (jit_enabled) {
776                  const char *str = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(w_jit_cache_size)->entry));
777                  PrefsReplaceInt32("jitcachesize", atoi(str));
778          }
755 #endif
779   }
780  
781   // Create "JIT Compiler" pane
782   static void create_jit_pane(GtkWidget *top)
783   {
784 < #if USE_JIT
784 >        if (!is_jit_capable())
785 >                return;
786 >
787          GtkWidget *box, *table, *label, *menu;
788          char str[32];
789          
# Line 784 | Line 809 | static void create_jit_pane(GtkWidget *t
809          w_jit_follow_const_jumps = make_checkbox(box, STR_JIT_FOLLOW_CONST_JUMPS, "jitinline", GTK_SIGNAL_FUNC(tb_jit_follow_const_jumps));
810  
811          set_jit_sensitive();
787 #endif
812   }
813  
814   /*
# Line 1409 | Line 1433 | static void create_serial_pane(GtkWidget
1433   static GtkWidget *w_ramsize;
1434   static GtkWidget *w_rom_file;
1435  
1436 + // Don't use CPU when idle?
1437 + static void tb_idlewait(GtkWidget *widget)
1438 + {
1439 +        PrefsReplaceBool("idlewait", GTK_TOGGLE_BUTTON(widget)->active);
1440 + }
1441 +
1442   // "Ignore SEGV" button toggled
1443   #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
1444   static void tb_ignoresegv(GtkWidget *widget)
# Line 1501 | Line 1531 | static void create_memory_pane(GtkWidget
1531  
1532          w_rom_file = table_make_file_entry(table, 4, STR_ROM_FILE_CTRL, "rom");
1533  
1534 +        make_checkbox(box, STR_IDLEWAIT_CTRL, "idlewait", GTK_SIGNAL_FUNC(tb_idlewait));
1535   #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
1536          make_checkbox(box, STR_IGNORESEGV_CTRL, "ignoresegv", GTK_SIGNAL_FUNC(tb_ignoresegv));
1537   #endif
# Line 1525 | Line 1556 | static void read_settings(void)
1556  
1557   #ifdef STANDALONE_GUI
1558   #include <errno.h>
1559 + #include <sys/wait.h>
1560 + #include "rpc.h"
1561  
1562   /*
1563   *  Fake unused data and functions
# Line 1533 | Line 1566 | static void read_settings(void)
1566   uint8 XPRAM[XPRAM_SIZE];
1567   void MountVolume(void *fh) { }
1568   void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) { }
1569 < void WarningAlert(const char *text) { }
1569 >
1570 > #if defined __APPLE__ && defined __MACH__
1571 > void DarwinAddCDROMPrefs(void) { }
1572 > void DarwinAddFloppyPrefs(void) { }
1573 > void DarwinAddSerialPrefs(void) { }
1574 > bool DarwinCDReadTOC(char *, uint8 *) { }
1575 > #endif
1576  
1577  
1578   /*
# Line 1576 | Line 1615 | static void display_alert(int title_id,
1615   *  Display error alert
1616   */
1617  
1618 < static void ErrorAlert(const char *text)
1618 > void ErrorAlert(const char *text)
1619   {
1620          display_alert(STR_ERROR_ALERT_TITLE, STR_GUI_ERROR_PREFIX, STR_QUIT_BUTTON, text);
1621   }
1622  
1623  
1624   /*
1625 + *  Display warning alert
1626 + */
1627 +
1628 + void WarningAlert(const char *text)
1629 + {
1630 +        display_alert(STR_WARNING_ALERT_TITLE, STR_GUI_WARNING_PREFIX, STR_OK_BUTTON, text);
1631 + }
1632 +
1633 +
1634 + /*
1635 + *  RPC handlers
1636 + */
1637 +
1638 + static GMainLoop *g_gui_loop;
1639 +
1640 + static int handle_ErrorAlert(rpc_connection_t *connection)
1641 + {
1642 +        D(bug("handle_ErrorAlert\n"));
1643 +
1644 +        int error;
1645 +        char *str;
1646 +        if ((error = rpc_method_get_args(connection, RPC_TYPE_STRING, &str, RPC_TYPE_INVALID)) < 0)
1647 +                return error;
1648 +
1649 +        ErrorAlert(str);
1650 +        free(str);
1651 +        return RPC_ERROR_NO_ERROR;
1652 + }
1653 +
1654 + static int handle_WarningAlert(rpc_connection_t *connection)
1655 + {
1656 +        D(bug("handle_WarningAlert\n"));
1657 +
1658 +        int error;
1659 +        char *str;
1660 +        if ((error = rpc_method_get_args(connection, RPC_TYPE_STRING, &str, RPC_TYPE_INVALID)) < 0)
1661 +                return error;
1662 +
1663 +        WarningAlert(str);
1664 +        free(str);
1665 +        return RPC_ERROR_NO_ERROR;
1666 + }
1667 +
1668 + static int handle_Exit(rpc_connection_t *connection)
1669 + {
1670 +        D(bug("handle_Exit\n"));
1671 +
1672 +        g_main_quit(g_gui_loop);
1673 +        return RPC_ERROR_NO_ERROR;
1674 + }
1675 +
1676 +
1677 + /*
1678 + *  SIGCHLD handler
1679 + */
1680 +
1681 + static char g_app_path[PATH_MAX];
1682 + static rpc_connection_t *g_gui_connection = NULL;
1683 +
1684 + static void sigchld_handler(int sig, siginfo_t *sip, void *)
1685 + {
1686 +        D(bug("Child %d exitted with status = %x\n", sip->si_pid, sip->si_status));
1687 +
1688 +        // XXX perform a new wait because sip->si_status is sometimes not
1689 +        // the exit _value_ on MacOS X but rather the usual status field
1690 +        // from waitpid() -- we could arrange this code in some other way...
1691 +        int status;
1692 +        if (waitpid(sip->si_pid, &status, 0) < 0)
1693 +                status = sip->si_status;
1694 +        if (WIFEXITED(status))
1695 +                status = WEXITSTATUS(status);
1696 +        if (status & 0x80)
1697 +                status |= -1 ^0xff;
1698 +
1699 +        if (status < 0) {       // negative -> execlp/-errno
1700 +                char str[256];
1701 +                sprintf(str, GetString(STR_NO_B2_EXE_FOUND), g_app_path, strerror(-status));
1702 +                ErrorAlert(str);
1703 +                status = 1;
1704 +        }
1705 +
1706 +        if (status != 0) {
1707 +                if (g_gui_connection)
1708 +                        rpc_exit(g_gui_connection);
1709 +                exit(status);
1710 +        }
1711 + }
1712 +
1713 +
1714 + /*
1715   *  Start standalone GUI
1716   */
1717  
# Line 1610 | Line 1739 | int main(int argc, char *argv[])
1739  
1740          // Transfer control to the executable
1741          if (start) {
1742 <                char b2_path[PATH_MAX];
1743 <                strcpy(b2_path, argv[0]);
1615 <                char *p = strrchr(b2_path, '/');
1616 <                p = p ? p + 1 : b2_path;
1617 <                *p = '\0';
1618 <                strcat(b2_path, "BasiliskII");
1619 <                argv[0] = b2_path;
1620 <                execv(b2_path, argv);
1742 >                char gui_connection_path[64];
1743 >                sprintf(gui_connection_path, "/org/BasiliskII/GUI/%d", getpid());
1744  
1745 <                char str[256];
1746 <                sprintf(str, GetString(STR_NO_B2_EXE_FOUND), b2_path, strerror(errno));
1747 <                ErrorAlert(str);
1748 <                return 1;
1745 >                // Catch exits from the child process
1746 >                struct sigaction sigchld_sa, old_sigchld_sa;
1747 >                sigemptyset(&sigchld_sa.sa_mask);
1748 >                sigchld_sa.sa_sigaction = sigchld_handler;
1749 >                sigchld_sa.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
1750 >                if (sigaction(SIGCHLD, &sigchld_sa, &old_sigchld_sa) < 0) {
1751 >                        char str[256];
1752 >                        sprintf(str, GetString(STR_SIG_INSTALL_ERR), SIGCHLD, strerror(errno));
1753 >                        ErrorAlert(str);
1754 >                        return 1;
1755 >                }
1756 >
1757 >                // Search and run the BasiliskII executable
1758 >                char *p;
1759 >                strcpy(g_app_path, argv[0]);
1760 >                if ((p = strstr(g_app_path, "BasiliskIIGUI.app/Contents/MacOS")) != NULL) {
1761 >                    strcpy(p, "BasiliskII.app/Contents/MacOS/BasiliskII");
1762 >                        if (access(g_app_path, X_OK) < 0) {
1763 >                                char str[256];
1764 >                                sprintf(str, GetString(STR_NO_B2_EXE_FOUND), g_app_path, strerror(errno));
1765 >                                WarningAlert(str);
1766 >                                strcpy(g_app_path, "/Applications/BasiliskII.app/Contents/MacOS/BasiliskII");
1767 >                        }
1768 >                } else {
1769 >                        p = strrchr(g_app_path, '/');
1770 >                        p = p ? p + 1 : g_app_path;
1771 >                        strcpy(p, "BasiliskII");
1772 >                }
1773 >
1774 >                int pid = fork();
1775 >                if (pid == 0) {
1776 >                        D(bug("Trying to execute %s\n", g_app_path));
1777 >                        execlp(g_app_path, g_app_path, "--gui-connection", gui_connection_path, (char *)NULL);
1778 > #ifdef _POSIX_PRIORITY_SCHEDULING
1779 >                        // XXX get a chance to run the parent process so that to not confuse/upset GTK...
1780 >                        sched_yield();
1781 > #endif
1782 >                        _exit(-errno);
1783 >                }
1784 >
1785 >                // Establish a connection to Basilisk II
1786 >                if ((g_gui_connection = rpc_init_server(gui_connection_path)) == NULL) {
1787 >                        printf("ERROR: failed to initialize GUI-side RPC server connection\n");
1788 >                        return 1;
1789 >                }
1790 >                static const rpc_method_descriptor_t vtable[] = {
1791 >                        { RPC_METHOD_ERROR_ALERT,                       handle_ErrorAlert },
1792 >                        { RPC_METHOD_WARNING_ALERT,                     handle_WarningAlert },
1793 >                        { RPC_METHOD_EXIT,                                      handle_Exit }
1794 >                };
1795 >                if (rpc_method_add_callbacks(g_gui_connection, vtable, sizeof(vtable) / sizeof(vtable[0])) < 0) {
1796 >                        printf("ERROR: failed to setup GUI method callbacks\n");
1797 >                        return 1;
1798 >                }
1799 >                int socket;
1800 >                if ((socket = rpc_listen_socket(g_gui_connection)) < 0) {
1801 >                        printf("ERROR: failed to initialize RPC server thread\n");
1802 >                        return 1;
1803 >                }
1804 >
1805 >                g_gui_loop = g_main_new(TRUE);
1806 >                while (g_main_is_running(g_gui_loop)) {
1807 >
1808 >                        // Process a few events pending
1809 >                        const int N_EVENTS_DISPATCH = 10;
1810 >                        for (int i = 0; i < N_EVENTS_DISPATCH; i++) {
1811 >                                if (!g_main_iteration(FALSE))
1812 >                                        break;
1813 >                        }
1814 >
1815 >                        // Check for RPC events (100 ms timeout)
1816 >                        int ret = rpc_wait_dispatch(g_gui_connection, 100000);
1817 >                        if (ret == 0)
1818 >                                continue;
1819 >                        if (ret < 0)
1820 >                                break;
1821 >                        rpc_dispatch(g_gui_connection);
1822 >                }
1823 >
1824 >                rpc_exit(g_gui_connection);
1825 >                return 0;
1826          }
1827  
1828          return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines