changing keymap from QWERTY to AZERTY in FreeBSD

hello,

I'm trying to get my FreeBSD PC to be in AZERTY so I can write proper French with accents and everything.
How do I do this?

I've tried making a small program called locale.c, which includes `<locale.h>` and uses the `setlocale(LC_ALL, "fr")` function, but I'm having the following errors when I try to compile it:
Code:
/usr/include/locale.h:66:17: note: expanded from macro 'LC_ALL'
   66 | #define LC_ALL          0
      |                         ^
locale.c:3:11: error: expected ')'
/usr/include/locale.h:66:17: note: expanded from macro 'LC_ALL'
   66 | #define LC_ALL          0
      |                         ^
locale.c:3:10: note: to match this '('
    3 | setlocale(LC_ALL, "fr");
      |          ^
locale.c:3:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    3 | setlocale(LC_ALL, "fr");
      | ^
      | int
locale.c:3:1: warning: a function declaration without a pr
[CODE]locale.c:3:11: error: expected parameter declarator
    3 | setlocale(LC_ALL, "fr");
      |           ^
/usr/include/locale.h:66:17: note: expanded from macro 'LC_ALL'
   66 | #define LC_ALL          0
      |                         ^
locale.c:3:11: error: expected ')'
/usr/include/locale.h:66:17: note: expanded from macro 'LC_ALL'
   66 | #define LC_ALL          0
      |                         ^
locale.c:3:10: note: to match this '('
    3 | setlocale(LC_ALL, "fr");
      |          ^
locale.c:3:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    3 | setlocale(LC_ALL, "fr");
      | ^
      | int
locale.c:3:1: warning: a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C23, conflicting with a previous declaration [-Wdeprecated-non-prototype]
/usr/include/locale.h:80:8: note: conflicting prototype is here
   80 | char            *setlocale(int, const char *);
      |                  ^
locale.c:3:1: error: conflicting types for 'setlocale'
    3 | setlocale(LC_ALL, "fr");
      | ^
/usr/include/locale.h:80:8: note: previous declaration is here
   80 | char            *setlocale(int, const char *);
      |                  ^
2 warnings and 3 errors generated.
 
In FreeBSD, setting the
locale does not change the keyboard language because the two settings control entirely separate aspects of the system.

  • The locale settings (configured via LANG, LC_* variables in files like ~/.login_conf or /etc/login.conf) control the language for menus, messages, character encoding (like UTF-8), and date/number formats. They define how the system displays information and interacts with character sets.
  • The keyboard layout (or keymap) defines the physical mapping of keys on your keyboard to specific characters. This is a separate, system-level configuration managed by specific tools for either the console or the graphical Xorg environment.
Code:
#include <stdlib.h>
#include <stdio.h>

int main() {
    // The command is executed by the shell
    int return_status = system("setxkbmap fr");
    //  int return_status = system("kbdcontrol -l fr.acc.kbd");
    if (return_status == -1) {
        perror("system");
    } else {
        printf("Command finished with status %d\n", return_status);
    }

    return 0;
}
 
Really cool to not only ignore my answer, but to make another thread where you post the same weird question. First time posting in a forum?
Hello, sorry for not replying to your answer earlier, I realized afterwards that I'd posted in the wrong sub-forum, couldn't figure out how to delete the thread, so I edited my post to say "wrong sub-forum; apologies".

I am sorry for my error, I hope you will forgive me, I have answered you in the other thread :)
---
 
In FreeBSD, setting the
locale does not change the keyboard language because the two settings control entirely separate aspects of the system.

  • The locale settings (configured via LANG, LC_* variables in files like ~/.login_conf or /etc/login.conf) control the language for menus, messages, character encoding (like UTF-8), and date/number formats. They define how the system displays information and interacts with character sets.
  • The keyboard layout (or keymap) defines the physical mapping of keys on your keyboard to specific characters. This is a separate, system-level configuration managed by specific tools for either the console or the graphical Xorg environment.
Code:
#include <stdlib.h>
#include <stdio.h>

int main() {
    // The command is executed by the shell
    int return_status = system("setxkbmap fr");
    //  int return_status = system("kbdcontrol -l fr.acc.kbd");
    if (return_status == -1) {
        perror("system");
    } else {
        printf("Command finished with status %d\n", return_status);
    }

    return 0;
}
Hello Alain De Vos,
thanks for your answer.
I tried your program with Sway, got an error
Code:
WARNING: Running setxkbmap against an Xwayland server
Command finished with status 0
I tried also directly typing
Code:
kbdcontrol -l fr.acc.kbd
and got
Code:
kbdcontrol: setting keymap: Inappropriate ioctl for device

I suspect the issue is I'm using Wayland instead of X11.

However, thanks to a reddit post, I was able to configure Sway to switch between layouts with the following in .config/sway/config
:
Code:
input type:keyboard {
    xkb_layout eu,fr
}

bindsym $mod+Ctrl+k input type:keyboard xkb_switch_layout next
 
With some other wayland compositor, you may need to export env var :
Code:
export XKB_DEFAULT_LAYOUT=fr
export XKB_DEFAUKT_VARIANT=oss
or just add xkb_variant "oss" to your sway config
PS: the oss variant add some chars like œ with alt-gr+o for example.
 
thanks for your reply bda65 :)

I'm using fish shell, so I tried
Code:
set -x XKB_DEFAULT_LAYOUT fr
set -x XKB_DEFAULT_LAYOUT oss
but the environment variables didn't actually seem to change anything.

I tried adding

xkb_variant oss

to sway config, like so:
Code:
input type:keyboard {
    xkb_layout eu,fr
    xkb_variant oss
}

got a configuration error when I tried reloading Sway:

'xkb_variant oss': Failed to compile keymap: {XKB-661] Couldn't process include staement for 'eu(oss)', so I just added `oss` as a third layout :)

Is there a way to visualize a keyboard layout? Like to get a printout of the keys?
 
Don't know but all is in a text file:
/usr/local/share/X11/xkb/symbols/fr
For the variant in your sway config, there's no oss for eu, only for fr. You may need to add a comma:
Code:
input type:keyboard {
    xkb_layout eu,fr
    xkb_variant ,oss
}
 
Back
Top