Showing posts with label Operating System. Show all posts
Showing posts with label Operating System. Show all posts

July 13, 2025

AI generated window desktop

 

A minimalist GUI prototype written in Python and pygame was generated with an AI. Its possible to click on the file bar but executing additional programs is not possible. The source code consists of 180 lines of code and was entirely created by a large language model:

import pygame
import sys

# --- Pygame Initialization ---
pygame.init()

# --- Screen Dimensions ---
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 700
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Pygame: Desktop Simulation")

# --- Colors ---
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
LIGHT_BLUE = (173, 216, 230)
LIGHT_GREEN = (144, 238, 144)
DARK_GRAY = (50, 50, 50)
TOOLBAR_GRAY = (70, 70, 70)
BUTTON_HOVER = (90, 90, 90)
BUTTON_ACTIVE = (120, 120, 120)

# --- Font for text ---
font_small = pygame.font.Font(None, 24) # For menu items, etc.
font_medium = pygame.font.Font(None, 30) # For window titles
font_large = pygame.font.Font(None, 36) # For main elements

# --- Desktop Background ---
desktop_bg_color = (60, 60, 100) # A dark blue/purple for a desktop feel

# --- Taskbar/Top Bar Properties ---
taskbar_height = 40
taskbar_rect = pygame.Rect(0, 0, SCREEN_WIDTH, taskbar_height)
start_button_rect = pygame.Rect(5, 5, 80, 30) # x, y, width, height
start_button_text = "Start"
start_menu_active = False
start_menu_rect = pygame.Rect(5, taskbar_height, 150, 150) # Example menu size
start_menu_items = ["Terminal", "Browser", "Editor", "Settings"]
start_menu_item_rects = [] # To store rects for click detection

# --- Window Properties (as classes for easier management) ---
class Window:
    def __init__(self, x, y, width, height, color, title, content_text=""):
        self.rect = pygame.Rect(x, y, width, height)
        self.title_bar_height = 25
        self.title_bar_rect = pygame.Rect(x, y, width, self.title_bar_height)
        self.content_rect = pygame.Rect(x, y + self.title_bar_height, width, height - self.title_bar_height)
        self.color = color
        self.title = title
        self.content_text = content_text
        self.active_menu_message = "" # To show what menu item was clicked

        # Menu button rects (File and Edit)
        self.file_menu_rect = pygame.Rect(self.title_bar_rect.x + 5, self.title_bar_rect.y + 2, 40, self.title_bar_height - 4)
        self.edit_menu_rect = pygame.Rect(self.title_bar_rect.x + 50, self.title_bar_rect.y + 2, 40, self.title_bar_height - 4)

    def draw(self, surface):
        # Draw window content area
        pygame.draw.rect(surface, self.color, self.content_rect)
        pygame.draw.rect(surface, BLACK, self.content_rect, 2) # Border

        # Draw title bar
        pygame.draw.rect(surface, TOOLBAR_GRAY, self.title_bar_rect)
        pygame.draw.rect(surface, BLACK, self.title_bar_rect, 2) # Border

        # Draw title text
        title_surface = font_medium.render(self.title, True, WHITE)
        title_rect = title_surface.get_rect(centerx=self.title_bar_rect.centerx, centery=self.title_bar_rect.centery)
        surface.blit(title_surface, title_rect)

        # Draw menu buttons (File, Edit)
        pygame.draw.rect(surface, DARK_GRAY, self.file_menu_rect)
        file_text = font_small.render("File", True, WHITE)
        file_text_rect = file_text.get_rect(center=self.file_menu_rect.center)
        surface.blit(file_text, file_text_rect)

        pygame.draw.rect(surface, DARK_GRAY, self.edit_menu_rect)
        edit_text = font_small.render("Edit", True, WHITE)
        edit_text_rect = edit_text.get_rect(center=self.edit_menu_rect.center)
        surface.blit(edit_text, edit_text_rect)

        # Draw content text
        content_surface = font_small.render(self.content_text, True, BLACK)
        content_rect = content_surface.get_rect(topleft=(self.content_rect.x + 10, self.content_rect.y + 10))
        surface.blit(content_surface, content_rect)

        # Draw active menu message
        if self.active_menu_message:
            message_surface = font_small.render(self.active_menu_message, True, BLACK)
            message_rect = message_surface.get_rect(topleft=(self.content_rect.x + 10, self.content_rect.y + 40))
            surface.blit(message_surface, message_rect)

    def handle_click(self, pos):
        if self.file_menu_rect.collidepoint(pos):
            self.active_menu_message = "File menu clicked!"
            return True
        elif self.edit_menu_rect.collidepoint(pos):
            self.active_menu_message = "Edit menu clicked!"
            return True
        return False

# Create our two custom windows
window1 = Window(100, 100, 350, 250, LIGHT_BLUE, "My Documents", "Welcome to Window One!")
window2 = Window(500, 350, 400, 280, LIGHT_GREEN, "Application", "This is Window Two.")

# --- Game Loop ---
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.MOUSEBUTTONDOWN:
            mouse_pos = event.pos

            # Handle Start button click
            if start_button_rect.collidepoint(mouse_pos):
                start_menu_active = not start_menu_active # Toggle menu visibility
            elif start_menu_active and start_menu_rect.collidepoint(mouse_pos):
                # Check if a start menu item was clicked
                for i, item_rect in enumerate(start_menu_item_rects):
                    if item_rect.collidepoint(mouse_pos):
                        # In a real app, you'd launch something here
                        print(f"Launched: {start_menu_items[i]}")
                        window1.content_text = f"Launched: {start_menu_items[i]}"
                        start_menu_active = False # Close menu after selection
            else: # If click outside start menu, close it
                start_menu_active = False

            # Handle clicks on window menus
            window1.active_menu_message = "" # Clear previous messages
            window2.active_menu_message = ""
            if window1.handle_click(mouse_pos):
                pass # Handled by window object
            elif window2.handle_click(mouse_pos):
                pass # Handled by window object

    # --- Drawing ---
    screen.fill(desktop_bg_color) # Desktop background

    # Draw Taskbar/Top Bar
    pygame.draw.rect(screen, TOOLBAR_GRAY, taskbar_rect)
    pygame.draw.rect(screen, BLACK, taskbar_rect, 1) # Border

    # Draw Start button
    pygame.draw.rect(screen, DARK_GRAY, start_button_rect)
    pygame.draw.rect(screen, BLACK, start_button_rect, 1)
    start_text_surface = font_medium.render(start_button_text, True, WHITE)
    start_text_rect = start_text_surface.get_rect(center=start_button_rect.center)
    screen.blit(start_text_surface, start_text_rect)

    # Draw Start Menu if active
    if start_menu_active:
        pygame.draw.rect(screen, TOOLBAR_GRAY, start_menu_rect)
        pygame.draw.rect(screen, BLACK, start_menu_rect, 2)
        start_menu_item_rects = [] # Clear and re-populate for current frame
        for i, item in enumerate(start_menu_items):
            item_y = start_menu_rect.y + 10 + i * 30
            item_rect = pygame.Rect(start_menu_rect.x + 5, item_y, start_menu_rect.width - 10, 25)
            start_menu_item_rects.append(item_rect)

            # Check for hover effect (optional but nice for menus)
            if item_rect.collidepoint(pygame.mouse.get_pos()):
                pygame.draw.rect(screen, BUTTON_HOVER, item_rect)

            item_text_surface = font_small.render(item, True, WHITE)
            item_text_rect = item_text_surface.get_rect(topleft=(item_rect.x + 5, item_rect.y + 2))
            screen.blit(item_text_surface, item_text_rect)


    # Draw Windows
    window1.draw(screen)
    window2.draw(screen)

    # --- Update the Display ---
    pygame.display.flip()

# --- Quit Pygame ---
pygame.quit()
sys.exit()

October 14, 2021

The filesystem as the core element of an operating system?

 

The thesis is formulated only as a question because it is a bit unclear what the situation is. Operating systems are usually perceived by their GUI. The windows OS has a certain form of window manager, and the Linux OS has a different one. But, an operating system has something which is located behind the surface which is the file system. Linux systems are working usually with the ext4 filesystem, Windows systems are based on NTFS and MacOS is working with APFS.
The interesting situation is that apart from the mentioned very powerful filesystems there are many others available for example the famous fat16 filesystem which was used in the MS-DOS age, or the ZFS filesystem which is used in FreeBSD. What these filesystems have in common is that they are completely incompatiable to each other. Even so called open source filesystems like ext4 are only available in Linux. Until today there is no simple to install software available for windows to mount ext4 formatted harddrive. Such a tool is only available for the btrfs filesystem, but btrfs is not used by most Linux users.
And other filesystems like NTFS are also not available for more than a single platform. It seems, that the different operating systems are using their filesystem to making their users dependent from them. But what exactly is the ordinary user doing with it's filesystem? The surprising insight is, that the use case scneraio is mostly the same between Windows and Linux users. In most cases the user has a home directory in which all the files are stored hierarchically. IN a network context additional filesystems are stored on a fileserver which results into more stored data measured in megabytes.
Let us talk about some limitations. All the following user requests can't be realized wit today's technology: installing Linux on the NTFS filesystem, installing Windows on the ext4 filesystem, reading ext4 usb sticks from Windows, writing to NTFS harddrives from WIndows, reading ext4 partitions from MAcOS, mounting Macos partitions in Linux. It seems, that the systems are not working very well together because of different reasons. In addition many new filesystems are created each year. The chance is high that in 4 years from today the ext4 filesystem is no longer used in Linux but replaced by something different.
The only standard available which is spoken by all major operating systems is FAT32. This outdated filesystem doesn't support journaling but at least it can be read and writing by most computers.

June 26, 2019

Real and fake operating systems


Sometimes, GNU Linux is compared with other operating systems like Windows 10 or Mac OS X with the aim to explain what the pros and cons are. The assumption is, that Mac OS X is an operating system which can be compared with Linux. Suppose, Linux is the only operating system which is available what exactly are Windows 10, Mac OS X and the OpenVMS system? To describe it we have to go back into computerhistory.
Let us take a look into pseudo operating systems from the past. The Amiga 500 had a preinstalled kickstart firmware which was able to display a GUI on the screen. The Atari ST was equipped with the GEM operating system, the IBM had a preinstalled MS-DOS, Apple computer were delivered with Mac OS, and IBM mainframes are using the AIX operating system. All these pseudo operating systems are working with the same principle in mind. The first fact is, that the sourcecode has no GPL license, and secondly, it's technically not possible to install the software on different hardware platform.
Let us take some examples. MS-DOS was an operating system in the 1980s. But it was not able to use MS-DOS on the Amiga 500 or on the IBM mainframe. That means, it was not a universal operating system which was able to manage any kind of hardware but it was designed for the IBM PCs needs. The same is true for the modern Mac OS X system which can't be installed on a Rasperry PI 3 computer nor an IBM mainframe computer. That is the reason why this software is not a real operating system. Sure, it is a layer between application programs and underlying hardware, but it is not universal for many different hardware plattforms but was designed as a firmware for a certain computer.
The same is true for the operating system built into the Nintendo Wii gaming console or which runs on most routers. In all these cases, the hardware manufactorer has developed a software for it's own device which is not open source and which can't be installed on a different device. The router firmware from device1 won't run on device2. The current situation in the computer industry is, that hundred and more different firmware systems are available. None of these can be called an operating system. The only true operating system which fulfills as the minimum requirement that it's open source and runs on many plattforms is Linux.
That means, it makes no sense to compare Linux with Windows 10, or compare Linux with Amiga 500 kickstart system. Because Linux is an operating system and the other type of software is a propriatary firmware of the hardware manufcatorer.
Somebody may argue, that there is no need for an operating because. For example, the Mac OS X firmware is well suited to handle the underlying hardware and the same is true for a router firmware. This argumentation results into today's landscape which consists of incompatible firmwares, missing standards and some kind of rant against the only operating system available which is Linux.
Let us think about possible alternatives to Linux. Which kind of software is available which runs everywhere? Right, exactly this is the bottleneck. There is no Linux alternative available. What is used on most computers and hardware devices are firmware systems which are maintained by a single hardware manufactorer and which are equal to the betamax system used in the 1980s on videorecorders before the VHS standard was invented. From the point of view of an Apple User, Mac OS X is great. It will boot the system and runs any application. But what will happen, if the user has advanced needs? Is Mac OS X able to run Linux applications, can the user plugin an external harddrive not certified by Apple? No he can't. Mac OS X, Amiga 500 kickstart and all the other Betamax like systems are developed for the need of the hardware manufactorers not with the customer in mind.
Somebody may argue, that Windows 10 is equal to an operating system standard because 95% of all the PCs are running with this firmware. But let us take a look into the limits of WIndows 10. Is the system able to boot server hardware, will it run on older PCs, can it be installed on a microcontroller, will Windows 10 run on a playstation? No it won't. Windows 10 was developed for the need of the PC industry. It will run on the x86 plattform and only on this hardware. Additionally, the specification is not available as open source and doesn't fulfill professional needs.
Windows 10 and Mac OS X are great example for well designed firmwares. They are optimized for a special purpose in mind and helped to sell a lot of computer hardware to the masses. But they are not different from firmware software from the past, for example SunOS or Palm OS. Which means on the longterm they can be ignored. If the IBM compatible PC is gone and if Apple is bankrupt, nobody will use this software anymore. Let us take a look what happens with the kickstart ROM from the Amiga 500. AFter Commodore was bankrupt, the project stopped. No updates were programmed anymore because outside of the Commodore world nobody was interested in an Amiga 500 firmware.
Requirements for a standard operating system
Instead of analyzing existing pseudo operating systems the better idea is to define first what purpose a standard operating system has to fulfill. The minimum requirement is, that it will run on all the hardware which is available: desktop PC, notebook, gaming console, tablet PC, smartphone, router, microcontroller, single server, cluster server. To make the Operating system a standard the sourcecode has to be available as open source, so that anybody can contribute to the development.
The GNU Linux project is the only available operating system which fulfills in parts the requirements. And if certain problems are available for example the Linux Android system is not fast enough on smartphone devices, than these detail problems can be solved within the existing ecosystem. The funny thing is, that Linux has no real competitor who is also trying to become a standard operating system which runs on all hardware. That means, the self-understanding of Windows, Mac OS X, HP-UX and proprietary router firmware is not to compete with Linux for the best operating system. Instead, these firmware software was designed for different needs. If Microsoft windows was planned as an alternative to Linux, than the software would be developed into a different direction. But Microsoft has decided, that Windows 10 is not a standard operating system, but a proprietary hardware depended firmware which is running on x86 hardware only.