Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
orbutils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
orbutils
Commits
e2f94048
Verified
Commit
e2f94048
authored
5 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
launcher and orblogin HiDPI
parent
ee07221b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/launcher/main.rs
+34
-24
34 additions, 24 deletions
src/launcher/main.rs
src/orblogin/main.rs
+28
-25
28 additions, 25 deletions
src/orblogin/main.rs
with
62 additions
and
49 deletions
src/launcher/main.rs
+
34
−
24
View file @
e2f94048
...
...
@@ -16,6 +16,7 @@ use std::os::unix::process::ExitStatusExt;
use
std
::
path
::
Path
;
use
std
::
process
::{
Child
,
Command
,
ExitStatus
};
use
std
::
rc
::
Rc
;
use
std
::
sync
::
atomic
::{
AtomicIsize
,
Ordering
};
use
event
::
EventQueue
;
use
orbclient
::{
EventOption
,
Renderer
,
Window
,
WindowFlag
,
K_ESC
};
...
...
@@ -30,8 +31,15 @@ use theme::{BAR_COLOR, BAR_HIGHLIGHT_COLOR, TEXT_COLOR, TEXT_HIGHLIGHT_COLOR};
mod
package
;
mod
theme
;
pub
const
ICON_SIZE
:
i32
=
48
;
pub
const
ICON_SMALL_SIZE
:
i32
=
32
;
static
SCALE
:
AtomicIsize
=
AtomicIsize
::
new
(
1
);
fn
icon_size
()
->
i32
{
48
*
SCALE
.load
(
Ordering
::
Relaxed
)
as
i32
}
fn
icon_small_size
()
->
i32
{
32
*
SCALE
.load
(
Ordering
::
Relaxed
)
as
i32
}
#[cfg(target_os
=
"redox"
)]
static
UI_PATH
:
&
'static
str
=
"/ui"
;
...
...
@@ -61,19 +69,19 @@ fn wait(status: &mut usize) -> usize {
fn
load_icon
(
path
:
&
str
)
->
Image
{
let
icon
=
Image
::
from_path
(
path
)
.unwrap_or
(
Image
::
default
());
if
icon
.width
()
==
ICON_SIZE
as
u32
&&
icon
.height
()
==
ICON_SIZE
as
u32
{
if
icon
.width
()
==
icon_size
()
as
u32
&&
icon
.height
()
==
icon_size
()
as
u32
{
icon
}
else
{
icon
.resize
(
ICON_SIZE
as
u32
,
ICON_SIZE
as
u32
,
orbimage
::
ResizeType
::
Lanczos3
)
.unwrap
()
icon
.resize
(
icon_size
()
as
u32
,
icon_size
()
as
u32
,
orbimage
::
ResizeType
::
Lanczos3
)
.unwrap
()
}
}
fn
load_icon_small
(
path
:
&
str
)
->
Image
{
let
icon
=
Image
::
from_path
(
path
)
.unwrap_or
(
Image
::
default
());
if
icon
.width
()
==
ICON_SMALL_SIZE
as
u32
&&
icon
.height
()
==
ICON_SMALL_SIZE
as
u32
{
if
icon
.width
()
==
icon_small_size
()
as
u32
&&
icon
.height
()
==
icon_small_size
()
as
u32
{
icon
}
else
{
icon
.resize
(
ICON_SMALL_SIZE
as
u32
,
ICON_SMALL_SIZE
as
u32
,
orbimage
::
ResizeType
::
Lanczos3
)
.unwrap
()
icon
.resize
(
icon_small_size
()
as
u32
,
icon_small_size
()
as
u32
,
orbimage
::
ResizeType
::
Lanczos3
)
.unwrap
()
}
}
...
...
@@ -110,14 +118,14 @@ fn draw_chooser(window: &mut Window, font: &Font, packages: &Vec<Package>, selec
let
mut
y
=
0
;
for
(
i
,
package
)
in
packages
.iter
()
.enumerate
()
{
if
i
as
i32
==
selected
{
window
.rect
(
0
,
y
,
w
,
ICON_SMALL_SIZE
as
u32
,
BAR_HIGHLIGHT_COLOR
);
window
.rect
(
0
,
y
,
w
,
icon_small_size
()
as
u32
,
BAR_HIGHLIGHT_COLOR
);
}
package
.icon_small
.draw
(
window
,
0
,
y
);
font
.render
(
&
package
.name
,
16.0
)
.draw
(
window
,
ICON_SMALL_SIZE
+
8
,
y
+
8
,
if
i
as
i32
==
selected
{
TEXT_HIGHLIGHT_COLOR
}
else
{
TEXT_COLOR
});
font
.render
(
&
package
.name
,
16.0
)
.draw
(
window
,
icon_small_size
()
+
8
,
y
+
8
,
if
i
as
i32
==
selected
{
TEXT_HIGHLIGHT_COLOR
}
else
{
TEXT_COLOR
});
y
+=
ICON_SMALL_SIZE
;
y
+=
icon_small_size
()
;
}
window
.sync
();
...
...
@@ -151,6 +159,8 @@ impl Bar {
let
(
width
,
height
)
=
orbclient
::
get_display_size
()
.expect
(
"launcher: failed to get display size"
);
SCALE
.store
((
height
as
isize
/
1600
)
+
1
,
Ordering
::
Relaxed
);
Bar
{
children
:
Vec
::
new
(),
packages
:
packages
,
...
...
@@ -160,7 +170,7 @@ impl Bar {
width
:
width
,
height
:
height
,
window
:
Window
::
new_flags
(
0
,
height
as
i32
-
ICON_SIZE
,
width
,
ICON_SIZE
as
u32
,
"Launcher"
,
0
,
height
as
i32
-
icon_size
(),
width
,
icon_size
()
as
u32
,
"Launcher"
,
&
[
WindowFlag
::
Async
,
WindowFlag
::
Borderless
]
)
.expect
(
"launcher: failed to open window"
),
selected
:
-
1
,
...
...
@@ -214,7 +224,7 @@ impl Bar {
let
text
=
self
.font
.render
(
&
self
.time
,
32.0
);
x
=
self
.width
as
i32
-
text
.width
()
as
i32
-
8
;
y
=
(
ICON_SIZE
-
text
.height
()
as
i32
)
/
2
;
y
=
(
icon_size
()
-
text
.height
()
as
i32
)
/
2
;
text
.draw
(
&
mut
self
.window
,
x
,
y
,
TEXT_HIGHLIGHT_COLOR
);
self
.window
.sync
();
...
...
@@ -301,8 +311,8 @@ fn bar_main() {
EventOption
::
Screen
(
screen_event
)
=>
{
bar
.width
=
screen_event
.width
;
bar
.height
=
screen_event
.height
;
bar
.window
.set_pos
(
0
,
screen_event
.height
as
i32
-
ICON_SIZE
);
bar
.window
.set_size
(
screen_event
.width
,
ICON_SIZE
as
u32
);
bar
.window
.set_pos
(
0
,
screen_event
.height
as
i32
-
icon_size
()
);
bar
.window
.set_size
(
screen_event
.width
,
icon_size
()
as
u32
);
true
},
EventOption
::
Quit
(
_
)
=>
return
Ok
(
Some
(())),
...
...
@@ -345,9 +355,9 @@ fn bar_main() {
let
mut
i
=
0
;
if
i
==
bar
.selected
{
let
start_h
=
bar
.start_packages
.len
()
as
u32
*
ICON_SMALL_SIZE
as
u32
;
let
start_h
=
bar
.start_packages
.len
()
as
u32
*
icon_small_size
()
as
u32
;
let
mut
start_window
=
Window
::
new_flags
(
0
,
bar
.height
as
i32
-
ICON_SIZE
-
start_h
as
i32
,
200
,
start_h
,
"Start"
,
0
,
bar
.height
as
i32
-
icon_size
()
-
start_h
as
i32
,
200
,
start_h
,
"Start"
,
&
[
WindowFlag
::
Borderless
]
)
.unwrap
();
...
...
@@ -388,10 +398,10 @@ fn bar_main() {
let
mut
y
=
0
;
for
(
j
,
_package
)
in
bar
.start_packages
.iter
()
.enumerate
()
{
if
mouse_y
>=
y
&&
mouse_y
<
y
+
ICON_SMALL_SIZE
{
if
mouse_y
>=
y
&&
mouse_y
<
y
+
icon_small_size
()
{
now_selected
=
j
as
i32
;
}
y
+=
ICON_SMALL_SIZE
;
y
+=
icon_small_size
()
;
}
if
now_selected
!=
selected
{
...
...
@@ -402,7 +412,7 @@ fn bar_main() {
if
!
mouse_left
&&
last_mouse_left
{
let
mut
y
=
0
;
for
package_i
in
0
..
bar
.start_packages
.len
()
{
if
mouse_y
>=
y
&&
mouse_y
<
y
+
ICON_SMALL_SIZE
{
if
mouse_y
>=
y
&&
mouse_y
<
y
+
icon_small_size
()
{
if
bar
.start_packages
[
package_i
]
.binary
==
"exit"
{
return
Ok
(
Some
(()));
}
else
{
...
...
@@ -413,7 +423,7 @@ fn bar_main() {
}
break
'start_choosing
;
}
y
+=
ICON_SMALL_SIZE
;
y
+=
icon_small_size
()
;
}
}
...
...
@@ -487,7 +497,7 @@ fn chooser_main(paths: env::Args) {
});
if
packages
.len
()
>
1
{
let
mut
window
=
Window
::
new
(
-
1
,
-
1
,
200
,
packages
.len
()
as
u32
*
ICON_SMALL_SIZE
as
u32
,
path
)
.expect
(
"launcher: failed to open window"
);
let
mut
window
=
Window
::
new
(
-
1
,
-
1
,
200
,
packages
.len
()
as
u32
*
icon_small_size
()
as
u32
,
path
)
.expect
(
"launcher: failed to open window"
);
let
font
=
Font
::
find
(
Some
(
"Sans"
),
None
,
None
)
.expect
(
"launcher: failed to open font"
);
let
mut
selected
=
-
1
;
...
...
@@ -516,10 +526,10 @@ fn chooser_main(paths: env::Args) {
let
mut
y
=
0
;
for
(
i
,
_package
)
in
packages
.iter
()
.enumerate
()
{
if
mouse_y
>=
y
&&
mouse_y
<
y
+
ICON_SIZE
{
if
mouse_y
>=
y
&&
mouse_y
<
y
+
icon_size
()
{
now_selected
=
i
as
i32
;
}
y
+=
ICON_SMALL_SIZE
;
y
+=
icon_small_size
()
;
}
if
now_selected
!=
selected
{
...
...
@@ -530,13 +540,13 @@ fn chooser_main(paths: env::Args) {
if
!
mouse_left
&&
last_mouse_left
{
let
mut
y
=
0
;
for
package
in
packages
.iter
()
{
if
mouse_y
>=
y
&&
mouse_y
<
y
+
ICON_SMALL_SIZE
{
if
mouse_y
>=
y
&&
mouse_y
<
y
+
icon_small_size
()
{
if
let
Err
(
err
)
=
Command
::
new
(
&
package
.binary
)
.arg
(
path
)
.spawn
()
{
println!
(
"launcher: failed to launch {}: {}"
,
package
.binary
,
err
);
}
break
'choosing
;
}
y
+=
ICON_SMALL_SIZE
;
y
+=
icon_small_size
()
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/orblogin/main.rs
+
28
−
25
View file @
e2f94048
...
...
@@ -103,6 +103,9 @@ fn login_command(username: &str, pass: &str, launcher_cmd: &str, launcher_args:
fn
login_window
(
launcher_cmd
:
&
str
,
launcher_args
:
&
[
String
],
font
:
&
Font
,
image
:
&
Image
,
image_mode
:
BackgroundMode
)
->
Option
<
Command
>
{
let
(
display_width
,
display_height
)
=
orbclient
::
get_display_size
()
.expect
(
"orblogin: failed to get display size"
);
let
s_u
=
(
display_height
/
1600
)
+
1
;
let
s_i
=
s_u
as
i32
;
let
s_f
=
s_i
as
f32
;
let
mut
window
=
Window
::
new_flags
(
0
,
0
,
display_width
,
display_height
,
"orblogin"
,
...
...
@@ -156,12 +159,12 @@ fn login_window(launcher_cmd: &str, launcher_args: &[String], font: &Font, image
x
,
y
);
let
x
=
(
window
.width
()
as
i32
-
216
)
/
2
;
let
y
=
(
window
.height
()
as
i32
-
164
)
/
2
;
window
.rect
(
x
,
y
,
216
,
164
,
Color
::
rgba
(
0
,
0
,
0
,
128
));
let
x
=
(
window
.width
()
as
i32
-
216
*
s_i
)
/
2
;
let
y
=
(
window
.height
()
as
i32
-
164
*
s_i
)
/
2
;
window
.rect
(
x
,
y
,
216
*
s_u
,
164
*
s_u
,
Color
::
rgba
(
0
,
0
,
0
,
128
));
font
.render
(
"Username:"
,
16.0
)
.draw
(
&
mut
window
,
x
+
8
,
y
+
8
,
Color
::
rgb
(
255
,
255
,
255
));
font
.render
(
"Password:"
,
16.0
)
.draw
(
&
mut
window
,
x
+
8
,
y
+
68
,
Color
::
rgb
(
255
,
255
,
255
));
font
.render
(
"Username:"
,
16.0
*
s_f
)
.draw
(
&
mut
window
,
x
+
8
*
s_i
,
y
+
8
*
s_i
,
Color
::
rgb
(
255
,
255
,
255
));
font
.render
(
"Password:"
,
16.0
*
s_f
)
.draw
(
&
mut
window
,
x
+
8
*
s_i
,
y
+
68
*
s_i
,
Color
::
rgb
(
255
,
255
,
255
));
redraw
=
true
;
}
...
...
@@ -180,26 +183,26 @@ fn login_window(launcher_cmd: &str, launcher_args: &[String], font: &Font, image
Color
::
rgb
(
29
,
29
,
29
)
};
let
x
=
(
window
.width
()
as
i32
-
200
)
/
2
;
let
mut
y
=
(
window
.height
()
as
i32
-
148
)
/
2
;
let
x
=
(
window
.width
()
as
i32
-
200
*
s_i
)
/
2
;
let
mut
y
=
(
window
.height
()
as
i32
-
148
*
s_i
)
/
2
;
y
+=
24
;
y
+=
24
*
s_i
;
{
window
.rect
(
x
,
y
,
200
,
28
,
if
item
==
0
{
active
}
else
{
inactive
});
window
.rect
(
x
+
2
,
y
+
2
,
196
,
24
,
Color
::
rgb
(
40
,
40
,
40
));
window
.rect
(
x
,
y
,
200
*
s_u
,
28
*
s_u
,
if
item
==
0
{
active
}
else
{
inactive
});
window
.rect
(
x
+
2
*
s_i
,
y
+
2
*
s_i
,
196
*
s_u
,
24
*
s_u
,
Color
::
rgb
(
40
,
40
,
40
));
let
mut
string
=
username
.to_string
();
if
item
==
0
{
string
.push
(
'|'
);
}
font
.render
(
&
string
,
16.0
)
.draw
(
&
mut
window
,
x
+
6
,
y
+
6
,
Color
::
rgb
(
255
,
255
,
255
));
font
.render
(
&
string
,
16.0
*
s_f
)
.draw
(
&
mut
window
,
x
+
6
*
s_i
,
y
+
6
*
s_i
,
Color
::
rgb
(
255
,
255
,
255
));
}
y
+=
60
;
y
+=
60
*
s_i
;
{
window
.rect
(
x
,
y
,
200
,
28
,
if
item
==
1
{
active
}
else
{
inactive
});
window
.rect
(
x
+
2
,
y
+
2
,
196
,
24
,
Color
::
rgb
(
40
,
40
,
40
));
window
.rect
(
x
,
y
,
200
*
s_u
,
28
*
s_u
,
if
item
==
1
{
active
}
else
{
inactive
});
window
.rect
(
x
+
2
*
s_i
,
y
+
2
*
s_i
,
196
*
s_u
,
24
*
s_u
,
Color
::
rgb
(
40
,
40
,
40
));
let
mut
string
=
String
::
new
();
for
_c
in
password
.chars
()
{
string
.push
(
'•'
);
...
...
@@ -207,16 +210,16 @@ fn login_window(launcher_cmd: &str, launcher_args: &[String], font: &Font, image
if
item
==
1
{
string
.push
(
'|'
);
}
font
.render
(
&
string
,
16.0
)
.draw
(
&
mut
window
,
x
+
6
,
y
+
6
,
Color
::
rgb
(
255
,
255
,
255
));
font
.render
(
&
string
,
16.0
*
s_f
)
.draw
(
&
mut
window
,
x
+
6
*
s_i
,
y
+
6
*
s_i
,
Color
::
rgb
(
255
,
255
,
255
));
}
y
+=
36
;
y
+=
36
*
s_i
;
{
window
.rect
(
x
,
y
,
200
,
28
,
Color
::
rgb
(
29
,
29
,
29
));
window
.rect
(
x
+
2
,
y
+
2
,
196
,
24
,
Color
::
rgb
(
39
,
72
,
105
));
let
text
=
font
.render
(
&
"Login"
,
16.0
);
text
.draw
(
&
mut
window
,
x
+
(
200
-
text
.width
()
as
i32
)
/
2
,
y
+
6
,
Color
::
rgb
(
255
,
255
,
255
));
window
.rect
(
x
,
y
,
200
*
s_u
,
28
*
s_u
,
Color
::
rgb
(
29
,
29
,
29
));
window
.rect
(
x
+
2
*
s_i
,
y
+
2
*
s_i
,
196
*
s_u
,
24
*
s_u
,
Color
::
rgb
(
39
,
72
,
105
));
let
text
=
font
.render
(
&
"Login"
,
16.0
*
s_f
);
text
.draw
(
&
mut
window
,
x
+
(
200
*
s_i
-
text
.width
()
as
i32
)
/
2
,
y
+
6
*
s_i
,
Color
::
rgb
(
255
,
255
,
255
));
}
window
.sync
();
...
...
@@ -287,13 +290,13 @@ fn login_window(launcher_cmd: &str, launcher_args: &[String], font: &Font, image
},
EventOption
::
Button
(
button_event
)
=>
{
if
!
button_event
.left
&&
mouse_left
{
let
x
=
(
window
.width
()
as
i32
-
216
)
/
2
;
let
y
=
(
window
.height
()
as
i32
-
164
)
/
2
;
let
x
=
(
window
.width
()
as
i32
-
216
*
s_i
)
/
2
;
let
y
=
(
window
.height
()
as
i32
-
164
*
s_i
)
/
2
;
if
mouse_x
>=
x
&&
mouse_x
<
x
+
216
&&
mouse_y
>=
y
&&
mouse_y
<
y
+
164
{
if
mouse_y
<
y
+
64
{
if
mouse_x
>=
x
&&
mouse_x
<
x
+
216
*
s_i
&&
mouse_y
>=
y
&&
mouse_y
<
y
+
164
*
s_i
{
if
mouse_y
<
y
+
64
*
s_i
{
item
=
0
;
}
else
if
mouse_y
<
y
+
128
{
}
else
if
mouse_y
<
y
+
128
*
s_i
{
item
=
1
;
}
else
{
if
let
Some
(
command
)
=
login_command
(
&
username
,
&
password
,
launcher_cmd
,
launcher_args
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment