Skip to content

Commit

Permalink
feat: allow swapping the positions of the editor and language icons
Browse files Browse the repository at this point in the history
  • Loading branch information
vyfor committed Jun 14, 2024
1 parent 4208646 commit afad2bb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lua/cord.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cord.config = {
show_repository = true,
show_cursor_position = false,
swap_fields = false,
swap_icons = false,
workspace_blacklist = {},
},
lsp = {
Expand Down Expand Up @@ -104,7 +105,8 @@ local function init(config)
blacklist_arr,
blacklist_len,
vim.fn.getcwd(),
config.display.swap_fields
config.display.swap_fields,
config.display.swap_icons
),
ffi.new(
'Buttons',
Expand Down
3 changes: 2 additions & 1 deletion lua/cord/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ local function init_discord(ffi)
const char** workspace_blacklist;
const int workspace_blacklist_len;
const char* initial_path;
const bool swap;
const bool swap_fields;
const bool swap_icons;
} InitArgs;
typedef struct {
const char* filename;
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct Config {
workspace_blacklist: Vec<String>,
buttons: Vec<ActivityButton>,
swap_fields: bool,
swap_icons: bool,
}

#[repr(C)]
Expand Down Expand Up @@ -69,6 +70,7 @@ pub struct InitArgs {
pub workspace_blacklist_len: i32,
pub initial_path: *const c_char,
pub swap_fields: bool,
pub swap_icons: bool,
}

#[repr(C)]
Expand Down Expand Up @@ -124,6 +126,7 @@ pub unsafe extern "C" fn init(
let vcs_text = ptr_to_string(args.vcs_text);
let workspace_text = ptr_to_string(args.workspace_text);
let swap_fields = args.swap_fields;
let swap_icons = args.swap_icons;
let workspace = find_workspace(&ptr_to_string(args.initial_path));

let buttons = if buttons_ptr.is_null() {
Expand Down Expand Up @@ -182,6 +185,7 @@ pub unsafe extern "C" fn init(
workspace_blacklist,
buttons,
swap_fields,
swap_icons,
});
INITIALIZED = true;
};
Expand Down Expand Up @@ -241,6 +245,7 @@ pub unsafe extern "C" fn update_presence(
args.problem_count,
START_TIME.as_ref(),
config.swap_fields,
config.swap_icons,
);

config
Expand Down Expand Up @@ -444,6 +449,7 @@ pub unsafe extern "C" fn update_presence_with_assets(
args.problem_count,
START_TIME.as_ref(),
config.swap_fields,
config.swap_icons,
);

config
Expand Down
17 changes: 13 additions & 4 deletions src/util/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub fn build_activity(
problem_count: i32,
timestamp: Option<&u128>,
swap_fields: bool,
swap_icons: bool,
) -> Activity {
let (state, details) = if filetype == "Cord.idle" {
(Some(details), None)
Expand All @@ -134,16 +135,24 @@ pub fn build_activity(
)
};

let (large_image, small_image) = if large_image.is_some() {
if swap_icons {
(Some(config.editor_image.clone()), large_image)
} else {
(large_image, Some(config.editor_image.clone()))
}
} else {
(Some(config.editor_image.clone()), None)
};

Activity {
state,
details,
assets: Some(ActivityAssets {
small_image: (large_image.is_some())
.then(|| config.editor_image.clone()),
small_image,
small_text: (!config.editor_tooltip.is_empty())
.then(|| config.editor_tooltip.clone()),
large_image: large_image
.or_else(|| Some(config.editor_image.clone())),
large_image,
large_text: Some(
large_text
.len()
Expand Down

0 comments on commit afad2bb

Please sign in to comment.