Serenity Operating System
at portability 116 lines 3.8 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include "AppletManager.h" 28#include "Compositor.h" 29#include "EventLoop.h" 30#include "Screen.h" 31#include "WindowManager.h" 32#include <AK/SharedBuffer.h> 33#include <LibCore/ConfigFile.h> 34#include <LibGfx/Palette.h> 35#include <LibGfx/SystemTheme.h> 36#include <signal.h> 37#include <stdio.h> 38 39int main(int, char**) 40{ 41 if (pledge("stdio video thread shared_buffer accept rpath wpath cpath unix proc fattr", nullptr) < 0) { 42 perror("pledge"); 43 return 1; 44 } 45 46 if (unveil("/res", "r") < 0) { 47 perror("unveil"); 48 return 1; 49 } 50 51 if (unveil("/tmp", "cw") < 0) { 52 perror("unveil"); 53 return 1; 54 } 55 56 if (unveil("/etc/WindowServer/WindowServer.ini", "rwc") < 0) { 57 perror("unveil"); 58 return 1; 59 } 60 61 if (unveil("/dev", "rw") < 0) { 62 perror("unveil"); 63 return 1; 64 } 65 66 struct sigaction act; 67 memset(&act, 0, sizeof(act)); 68 act.sa_flags = SA_NOCLDWAIT; 69 act.sa_handler = SIG_IGN; 70 int rc = sigaction(SIGCHLD, &act, nullptr); 71 if (rc < 0) { 72 perror("sigaction"); 73 return 1; 74 } 75 76 auto wm_config = Core::ConfigFile::open("/etc/WindowServer/WindowServer.ini"); 77 auto theme_name = wm_config->read_entry("Theme", "Name", "Default"); 78 79 auto theme = Gfx::load_system_theme(String::format("/res/themes/%s.ini", theme_name.characters())); 80 ASSERT(theme); 81 Gfx::set_system_theme(*theme); 82 auto palette = Gfx::PaletteImpl::create_with_shared_buffer(*theme); 83 84 WindowServer::EventLoop loop; 85 86 if (pledge("stdio video thread shared_buffer accept rpath wpath cpath proc", nullptr) < 0) { 87 perror("pledge"); 88 return 1; 89 } 90 91 WindowServer::Screen screen(wm_config->read_num_entry("Screen", "Width", 1024), 92 wm_config->read_num_entry("Screen", "Height", 768)); 93 WindowServer::Compositor::the(); 94 auto wm = WindowServer::WindowManager::construct(*palette); 95 auto am = WindowServer::AppletManager::construct(); 96 auto mm = WindowServer::MenuManager::construct(); 97 98 if (unveil("/tmp", "") < 0) { 99 perror("unveil"); 100 return 1; 101 } 102 103 if (unveil("/dev", "") < 0) { 104 perror("unveil"); 105 return 1; 106 } 107 108 if (unveil(nullptr, nullptr) < 0) { 109 perror("unveil"); 110 return 1; 111 } 112 113 dbgprintf("Entering WindowServer main loop.\n"); 114 loop.exec(); 115 ASSERT_NOT_REACHED(); 116}