#Desktop Applications
Graphical applications arose in the early 80s as we moved from text-based terminals to more technically capable systems. This was part of the Personal Computer (PC) movement of that time, which aimed to put a “computer in every home”. Introduced in 1984, the Apple Macintosh introduced the first successful commercial graphical operating system; other vendors (e.g. Microsoft, Commodore, Sun) quickly followed suit with their own graphical operating systems. The conventions that were introduced on the Mac quickly became standard on other platforms.
Graphical User Interfaces (GUIs) were based on keyboard and mouse-input, and a graphical output (typically a CRT monitor). Such systems were seen as more "approachable" and "easy-to-use" for novice users, and were a major driver to the modern PC era.
{
Desktop applications refers to graphical applications designed for a notebook or desktop computer, typically running Windows, macOS or Linux. Users interact with these applications using a mouse and keyboard, although other devices may also be supported (e.g. camera, trackpad).
Modern graphical desktop applications closely resemble their earlier counterparts, and still rely heavily on point-and-click interaction. Modern operating systems have mostly been reduced to Linux, macOS and Windows.

There are obvious benefits to a graphical display being able to display rich colours, graphics and multimedia. However, point-and-click interfaces also provide other benefits:
- The interface provides affordances: visual suggestions on how you might interact with the system. This can include hints like tooltips, or a graphical design that makes use of controls obvious (e.g. handles to show where to "grab" a window corner).
- Systems provide continuous feedback to users. This includes obvious feedback (e.g. dialog boxes, status lines) and more subtle, continuous feedback (e.g. widgets animating when pressed).
- Interfaces are explorable: users can use menus, and cues to discover new features.
- Low cost of errors: undo-redo, and the ability to rollback to previous state makes exploration low-risk.
- These environments encouraged developers to use consistent widgets and interactive elements. Standardization led to a common look-and-feel, and placement of common controls - which made software easier to learn, especially for novices. Many of the standard features that we take for granted are a direct result of this design standardization in the 80s1.
#Getting started
#Create a new project
To create a Compose Multiplatform project, use the project wizard in IntelliJ IDEA, and select Compose for Desktop
as your project.

#Add Compose to a project
You can add also add Compose libraries to an existing project by extending your build.gradle.kts
file to include the appropriate plugin and dependencies.
#Create a main method
Your entry point for a desktop application is the main
method. For a Compose application, you need to:
- use a
main
method as its entry point, - declare a top-level
application
scope, - declare one or more windows within that application scope.
This is a simple application to display a window (in fact, it's the simplest possible way to do this).

Import statements
To make samples easier to read, we're going to stop including the import
statements when demonstrating code snippets. If you copy-paste any samples into IntelliJ, you will need to add the imports back so that it will compile. To do this, use the Show Context Actions
menu (ALT-ENTER) over any offending code:

#Compile and package
Use the Gradle menu (View
> Tool Windows
> Gradle
).

#Window support
The example above limits us to a single windows, which isn't always desireable. Graphical desktop applications also need to suuport the following:
- Multiple application windows. Most applications will often present their interface within a single, interactive window, but it can sometimes be useful to have multiple simultaneous windows controlled by a single application2.
- Full-screen and windowed interaction: although graphical applications tend to run windowed, they should usable full-screen as well. The window contents should scale or reposition themselves as the window size changes.
- Window decorations: Each window should have a titlebar, minimize/maximize/restore buttons (that work as expected).
A more flexible solution is to use an expanded syntax which allows us to create and manage multiple windows. Compose will create them with min/max/restore buttons based on the defaults for the existing operating system.
application
and Window
are top-level composables.
Window
accepts a number of parameters, including title
and onCloseRequest
, which is an event handler that fires when the window closes (we're calling the built-in exitApplication
method to quit when the window closes).
#Set window position and size
You can set the initial position and size of the window using the WindowState
parameter. Here's an example of specifying a number of window characteristics.
#Create multiple windows
Using this expanded syntax, you can add multiple windows using the Window()
composable!

#Minimize to the system tray

#Keyboard and mouse input
We should be able to handle:
- Point-and-click interaction using a mouse.
- Keyboard input, leveraging OS support for different keyboards.
- Keyboard shortcuts, appropriate to the operating system 3. This is often combined with menubars and menu items. For example,
- Ctrl-N for File-New, Ctrl-O for File-Open, Ctrl-Q for Quit.
- Ctrl-X for Cut, Ctrl-C for Copy, Ctrl-V for Paste.
- F1 for Help.
#Handle keyboard Input

#Handle mouse input
Composables have handlers for onClick
(single-click), onDoubleClick
and onLongClick
(press). You can assign functions to each of these handlers, which are executed when the input is detected.

The following code demonstrates how to track mouse movement through x, y positions.


#Advanced desktop
We've already reviewed how Composables are interactive elements that we can customize (see Compose). The section below details functionality which is specific to desktop.
#Set the application icon
To change the application icon, you need to include an icon image file in your project resources, and then tell to Compose Desktop to use it when building installer images. For example:
#Draw on a canvas
We can draw primitive graphics on a canvas.

#Show a dialog
We can show standard OS dialogs using the Dialog composable.
Notice that Windows, macOS, Linux all share a very common interaction paradigm, and a common look-and-feel! You can move between operating systems and be quite comfortable because of this.↩
Photoshop, for instance, famously has multiple windows tiled over the desktop. It's also a very, very complex program, so it needs to split up functionality like this.↩
Ctrl on Windows and Linux, CMD on Mac.↩